Jump to content

detecting a cron


drifter

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.