0

We distribute a PHP application that requires a scheduled task to be created to run a PHP script. I know how to do this. What I am trying to work out is the way to make this as simple as possible for the admin installing the software to set this up (ideally almost one click).

The problems:

i) We don't know where PHP is installed ii) We don't know where they have installed the file that we need to run.

My initial plan was to create a .bat file contains the path to PHP (so they would need to edit this file) and this loads our PHP script so is what they would need to create a scheduled task to run. Then there would be a second .bat file that would create the scheduled task itself (not entirely sure how to do that part).

Does this seem like the best approach? If so, any pointers on how to create a scheduled task using a .bat file - I can't find this information.

2 Answers 2

1

There is command "at" you can use in your .bat files to create scheduled task however it needs to be run as an admin.

Edit: schtasks does the same and may be used without admin rights.

You may search for php.exe, but it's little tricky - basically you need to use dir with /s parameter.

Why not inno setup for e.g.?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. schtasks looks perfect here. What do you mean by "Why not inno setup for e.g.?"
You may use fully functional setup software like inno setup instead .bat files - it should gave you a few more tools and user friendly interface.
1

To run PHP scripts from bat files you can simply create ".bat" files and add your file path. Below is example:

  1. create "your_file_name.bat"
  2. open in editplus or notepad and type:

rename your filename in below example

"D:\Program Files (x86)\EasyPHP-5.3.8.0\php\php.exe" "D:\Program Files (x86)\EasyPHP-5.3.8.0\www\project_name\your_script_name.php" >> log_new.txt
rem "D:\Program Files (x86)\EasyPHP-5.3.8.0\php\php.exe" your_script_name.php
pause
  • That's it, you are done.
  • log.txt will log whatever output or error generated by php file.

Hope this will solve your issue :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.