Contact Us
Call Now WhatsApp Open Ticket
How Do I Check if Cron job is Working? - Knowledgebase - Dr Web Host

How Do I Check if Cron job is Working? Print

  • 1

1) Create a blank text document named cron_test.txt and upload it into your script’s folder. Change the CHMOD settings or permissions on it to 777 so that its writable by the server.

2) Create a new PHP file called “cron_test.php”. This script will basically execute a task of writing a line of details to cron_test.txt you created in Step 1.

 

<?php
$crontext = "Cron Run at ".date("r")." by ".$_SERVER['USER']."\n" ;
$folder = substr($_SERVER['SCRIPT_FILENAME'],0,strrpos($_SERVER['SCRIPT_FILENAME'],"/")+1);
$filename = $folder."cron_test.txt" ;
$fp = fopen($filename,"a") or die("Open error!");
fwrite($fp, $crontext) or die("Write error!");
fclose($fp);
echo "Wrote to ".$filename."\n\n" ;
?>

 

 

3) Enter the following line to your Crontab or CPanel if you’re using one.

* * * * * php /yourfolder/cron_test.php

 

4) You should be able to see all the execution data on “cron_test.txt”.


Was this answer helpful?

« Back