Setup Cron Job with PHP without crontab that runs every minute.
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. generelly every hosting providers provide some programs like cPanel. Here we run a cron job that runs every mintues automatically without cron tab unix / linux demon or without any externel progams.
Generelly Cron job will run atleast 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.
Remmber this cron job runs with curl php extension.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | //This function runs with curl extension that calls or open remote file. function call_remote_file($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); } function do_somework(){ //This function to run every minutes @mail('mahesh@gmail.com','cron job','cron runned'); } set_time_limit(0); // 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.maheshchari.com/cronjob.php"; //it is the script that runs exactly every minutes call_remote_file($url); 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 commonds.
- No script php exec permissions.
- No need to turn off php safe mode.
Download Demo
Popularity: 8% [?]