Re: Re: Is CRON'd PHP script already running?

From: Date: Thu, 04 Oct 2001 09:08:41 +0000
Subject: Re: Re: Is CRON'd PHP script already running?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-69912@lists.php.net to get a copy of this message
Hi, Simon! You can either use semaphore functions if your PHP-build supports that. http://www.php.net/manual/en/ref.shmop.php BTW, Richard is absolutely right by what mentioned in his note. ----- Original Message ----- From: "Richard Lynch" <ceo@l-i-e.com> To: "Simon Kimber" <simon@funny.co.uk> Cc: <php-general@lists.php.net> Sent: Saturday, September 22, 2001 5:11 AM Subject: [PHP] Re: Is CRON'd PHP script already running? > <?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 > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#69912) next »