drifter Posted December 13, 2006 Share Posted December 13, 2006 is it possible to detect if another cron is running?I have a script that I run ever X minutes. in the even it fails, the next time the script will just process 2X blocks, fail again then 3x blocks etc.Now if something happens and the script gets behind from several failures in a row (ftp and soap source involved, so failure here is out of my control), or large amounts of data, the cron job may not be done running by the next time the script is called.So I want to know if there is a way that when running one php cron, I can check if there is another instance of it already running, and if so do not start the new one.Is this possible?Scott Link to comment https://forums.phpfreaks.com/topic/30564-detecting-a-cron/ Share on other sites More sharing options...
Pezmc Posted December 13, 2006 Share Posted December 13, 2006 Coult you make cron one set a start time at the beggining of the script and end time at the end in a database?Then the second script checks if the script end it not null in the data base and else it runs the cron? Link to comment https://forums.phpfreaks.com/topic/30564-detecting-a-cron/#findComment-140716 Share on other sites More sharing options...
kenrbnsn Posted December 13, 2006 Share Posted December 13, 2006 Take a look at the file locking functions [url=http://www.php.net/flock]flock()[/url].Have the script try to take out an exclusive lock on a file. If it can get it, do the processing, and release the lock when it's done. If it can't get it, just exit. This should guarantee that only one script is running at any time.Ken Link to comment https://forums.phpfreaks.com/topic/30564-detecting-a-cron/#findComment-140719 Share on other sites More sharing options...
drifter Posted December 13, 2006 Author Share Posted December 13, 2006 Thanks guys - both excellent ideas - off to read some. Link to comment https://forums.phpfreaks.com/topic/30564-detecting-a-cron/#findComment-140721 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.