Cron job is scheduling some tasks with in regular interval on server.To setup cron job we must know about the cron tab commonds and shell access to remote server. generally every hosting providers provide some programs like cPanel. Here we run a cron job that runs every minutes automatically without corn tab unix / linux demon or without any external programs.
Generally Cron job will run at least four hours gap on cPanel or Plesk ,so it is not possible to setup cron job every minute unless you have crontab demon on server , SSH account on server. Here we write a simple php script that calls itself at every minute.
Remember this cron job runs with curl php extension.
//This function runs with curl extension that calls or open remote file.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
//This function to run every minutes
@mail('[email protected]','cron job','cron executed');
// some web hosts will have only 30 sec max execution time so we keep it unlimited time
// this function only runs if safe mode is off
$url="http://www.arjun.net.in/cronjob.php"; //it is the script that runs exactly every minutes
do_somework();//in mean time run some work
sleep(60); // wait the script for 60 seconds or every minute
call_remote_file($url); // call this script itself after a minute
// This process continues every minute
To stop this cron job simple remove the file from server.
With this script we don’t need
- SSH /SFTP account
- No need of learning cron tab commons.
- No script php exec permissions.
- No need to turn off php safe mode.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.