<?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 [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
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 <[EMAIL PROTECTED]>
Newsgroups: php.general
To: <[EMAIL PROTECTED]>
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to