How do I run a PHP script using windows schedule task?
Locate the php.exe executable on your system and pass it the name of the script file using the -f
parameter.
Example:
C:\Xampp\php\php.exe -f C:\Xampp\htdocs\my_script.php
Reference:
- Introduction to using PHP on the command line
- PHP command line options
PHP script in windows task scheduler
I solve it by running my PHP script through batch file.
and scheduling the batch file in Windows task scheduler.
this post helped me so much:
http://www.devside.net/wamp-server/running-php-scripts-as-cron-jobs-on-windows
Run PHP script with Windows Task Scheduler, including files fails
this should work:
cd /D "D:\xampp\htdocs\MyApp\App\Cronjobs\"
"D:\xampp\php\php.exe" -f CronjobBase.php MyCronJob
OR:
D:
cd "D:\xampp\htdocs\MyApp\App\Cronjobs\"
"D:\xampp\php\php.exe" -f CronjobBase.php MyCronJob
Creating A Scheduled Task on PHP Running Under IIS
You could use Task Scheduler on the server to run a batch file that runs the PHP script via command line at a regular interval, which i hope should solve your problem.
How can I run a PHP Script automatically Daily in WAMP / Windows Environment?
You can do this with windows scheduler with command php full\link\to\php\file.php
, if this not working probably link to php.exe
file is not properly linked in systems PATH
variable. So you can try then something like this C:\wamp\bin\php\php5.5.12\php.exe C:\wamp\www\test.php
.
Also you can use at
cmd command to set up schedule task, you can read more about it here
Solution:
PHP File:
<?php
$myfile = fopen("H:\\wamp\\www\\file\\newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
BAT File:
H:\wamp\bin\php\php5.5.12\php.exe H:\wamp\www\file\file.php
Double Click BAT File will Create a newfile.txt.
Related Topics
Execute Commands on Remote MAChine via PHP
How to Chain Method on a Newly Created Object
How to Send Email from Localhost Wamp Server to Send Email Gmail Hotmail or So Forth
Exception: Serialization of 'Closure' Is Not Allowed
Posting Multidimensional Array with PHP and Curl
MySQL - Count Total Number of Rows in PHP
How to Add Anchor Tag to a Url from Text Input
JavaScript Equivalent of PHP's List()
Check Whether $_Post-Value Is Empty
How to Force a File to Download in PHP
PHP Move_Uploaded_File() Error
Multidimensional Array Array_Sum
PHP Script Not Working in HTML File
500 Internal Server Error, How to Debug