note 94530 deleted from function.getmypid by danbrown

From: Date: Tue, 10 Nov 2009 15:33:42 +0000
Subject: note 94530 deleted from function.getmypid by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162702@lists.php.net to get a copy of this message
Note Submitter: ercbluemonday at yahoo dot com ---- We also had this challenge in our company to prevent a php script in a cron job from overlapping each other. We made this solution <?php // Initialize variables $found = 0; $file = basename(__FILE__); $commands = array(); // Get running processes. exec("ps w", $commands); // If processes are found if (count($commands) > 0) { foreach ($commands as $command) { if (strpos($command, $file) === false) { // Do nothin' } else { // Let's count how many times the file is found. $found++; } } } // If the instance of the file is found more than once. if ($found > 1) { echo "Another process is running.\n"; die(); } /** * * Regular process here... * */ ?>

« previous php.notes (#162702) next »