How to test a cron job in Local Server like WAMP? How to test a cron job in Local Server like WAMP? windows windows

How to test a cron job in Local Server like WAMP?


Windows doesn't have Cron (it is the main task scheduling program for Linux systems). The Windows version for that is the Task Scheduler. This question recommends using the at command.

So that Cron doesn't have anything to do with the Apache, Mysql, PHP setup I don't think it is possible to reliably test the cronjobs you created for the Linux Cron in windows (maybe with Cygwin).


You can create a html page and open it on browser. The javascript setInterval function will call for specified periods.

Following is the code to do this. Specify your interval (5000 eg. which runs every 5sec)

<html><head>    <title>Cron</title></head><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><body><h1>Cron page</h1><script type="text/javascript">    setInterval(function(){        $.get('http://localhost/test/test.php', function(data) {            console.log(data);         });    }, 5000);</script></body></html>

Note: To avoid CORS you should call ajax from same host or allow CORS from server side.


You can run this:

set_time_limit(0);ignore_user_abort(true);while (1){    //your code here....    sleep($timetowait);}

You can close your browser the script will continue

set_time_limit(0); make your script work with no time limitation

sleep($timetowait); determine the time to wait before executing the next loop of while()

ignore_user_abort(true); let the script continue even if browser is closed

while(1) is an infinite loop, so this will never stop until you exit wamp.