PHP Script to Test Crontab


Sometimes, you want to know if your crontab is working or not, you would need to test your crontab to see if crontab jobs will be actually executed and how frequently will they be invoked. The following is a easy way to test it in PHP:

1
2
3
4
5
6
7
<php
date_default_timezone_set('UTC');
$fh = fopen('/home/helloacm.com/crontab.txt', 'a');
echo $fh;
echo fwrite($fh, date('Y-m-d H:i:s') . "\r\n");
fclose($fh);
?>
<php
date_default_timezone_set('UTC');
$fh = fopen('/home/helloacm.com/crontab.txt', 'a');
echo $fh;
echo fwrite($fh, date('Y-m-d H:i:s') . "\r\n");
fclose($fh);
?>

Save the above in a file e.g. test.php and use tool like crontab generator to generate the line to be inserted into crontab -e (to list the jobs, using command crontab -l).

Later, based on the content of the file crontab.txt you can check if the crontab jobs has been scheduled to execute.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
212 words
Last Post: Google Talk supports (y)
Next Post: Curly Brace Group in Linux BASH

The Permanent URL is: PHP Script to Test Crontab

Leave a Reply