Run Cron Job on PHP Script, on localhost in Windows
recently I had sort of problems to run a cron job on a php script on localhost (WAMP server) in windows 7, when I was on a test to chronically fetch some links from www out there.
By the way I am sharing this for anyone that is on the same thing.
You will need a shellscript to run chronically, using Windows Task Scheduler. Also you will need a batch script (script.bat) to call the php.exe and run your php script (here called as my_process.php
)
shellscript.vbs
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "C:\path\to\script\script.bat" & Chr(34), 0
Set WinScriptHost = Nothing
script.bat
"C:\wamp\bin\php\php5.4.12\php.exe" -f "C:\wamp\www\website\my_process.php"
Now, we are ready to set the Windows Task Scheduler to run shellscript.vbs at the required time interval:
- Open Task Scheduler from windows Start menu
- Go to Action menu and hit Create Task...
- in General tab, fill the Name and Description fields as you want
- in Triggers tab, hit New button.
- from Begin the Task dropdown, select On a schedule and choose Daily
- from Advanced settings section, select Repeat task every as you want and set for a duration on Indefinitely.
- on Actions tab, from Action dropdown, select Start a program.
- on the Program\script box, enter path to shellscript.vbs like C:\path\to\shellscript.vbs.
- leave Add argumentts (optional) section empty.
- in Start in (optional) box, enter parent directory of shellscript.vbs like
C:\path\to\
. - Hit upvote on this tutorial :) Have fun.
How to use cron job on localhost in Windows with Laravel 5
It doesn't work because php.exe
is supposed to execute a PHP file. When you point it to a URL it doesn't know what to do.
What you need is something like curl for Windows and then you can make a HTTP request:
curl http://localhost/test-cron-job
Run a php script on localhost using cron job
This is not an answer, but only pointers you need to check before you proceed further.
Crons are available only on unix systems, not windows.
While debugging cron or anything similar, schedule them for every minute or (any such acceptable smaller frequency), and once they work every minute, only then schedule them for the original frequencies. That will save you some time during debugging.
Its an incorrect call to exec. You don't have to pass all those
*
in itSince this is windows, You want to do
php.exe
and notC:\BitNami\wampstack-5.4.21-0\php -f
which would have been done in linux (with proper path)Your
.bat
file is currently scheduled daily, you need to schedule it every half hour.
php script with cron-like feature on Wamp windows
I gues you should just use windows task scheduler, but if you really need a php
script, you can use something like:
<?php
set_time_limit(0); // no time limit to execute the script
ignore_user_abort(true); //ignore if the user closes the browser or shell session
while(1){
echo 'Start<br>';
sleep(5);
echo 'End<br>';
}
?>
can i configure cron job for localhost
Cron is a time-based job scheduler in Unix-like computer operating systems. Which means you can not configure it on Windows.
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.
Related Topics
Enabling Postgresql Support in PHP on MAC Os X
What Does Using a Single Pipe '|' in a Function Argument Do
PHP 5.4 - 'Closure $This Support'
Post to a Facebook User's Wall with Curl PHP
How to Test If a User Has Selected a File to Upload
Multiple Submit Buttons PHP Different Actions
Finding the Minimum Value's Key in an Associative Array
Laravel Eloquent, Group by Month/Year
Jquery Using Ajax to Send Data and Save in PHP
Max File Number Can PHP Upload at Same Time
Double Not (!!) Operator in PHP
How to Get All Class Names Inside a Particular Namespace
How to Check That an Object Is Empty in PHP
Is HTMLentities() Sufficient for Creating Xml-Safe Values
How to Use "Root" Namespace of PHP