Re: Is CRON'd PHP script already running?

From: Date: Sat, 22 Sep 2001 03:11:08 +0000
Subject: Re: Is CRON'd PHP script already running?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-68260@lists.php.net to get a copy of this message
<?php # Untested code: exec("ps auxwww | grep $PHP_SELF", $results, $error); if ($error){ echo implode("\n", $results); echo "OS Error: $error Usually path/permissions. See 'man errno' to be sure\n"); } $results = implode("\n", $results); if (strstr($results, $PHP_SELF)){ # There's one of me already running. Die. exit(0); } . . . ?> NOTE: The file-locking and other solutions presented so far have a fatal flaw: If something pukes, the lock will be left behind and your PHP will never run again until you manually remove it. If you can get this working, that won't be an issue. -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm ----- Original Message ----- From: Simon Kimber <simon@funny.co.uk> Newsgroups: php.general To: <php-general@lists.php.net> Sent: Thursday, September 20, 2001 12:13 PM Subject: Is CRON'd PHP script already running? > Hi All, > > I have a PHP script that i want to run every few minutes (via cron) but I > only want it to run if it isn't already running. > > Is there something in cron itself to solve this or is there a way within PHP > to detect that another instance of the current script is running and if so > exit the new instance before it does anything... > > eg. I could have a function to use like so: > > if (already_running($SCRIPT_NAME)) { > exit(); > } > > Thanks in advance! > > Simon >

« previous php.general (#68260) next »