note 94530 added to function.getmypid

From: Date: Tue, 10 Nov 2009 12:40:20 +0000
Subject: note 94530 added to function.getmypid
Groups: php.notes 
Request: Send a blank email to php-notes+get-162697@lists.php.net to get a copy of this message
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... * */ ?> ---- Server IP: 69.147.83.197 Probable Submitter: 116.50.176.198 ---- Manual Page -- http://www.php.net/manual/en/function.getmypid.php Edit -- https://master.php.net/note/edit/94530 Del: integrated -- https://master.php.net/note/delete/94530/integrated Del: useless -- https://master.php.net/note/delete/94530/useless Del: bad code -- https://master.php.net/note/delete/94530/bad+code Del: spam -- https://master.php.net/note/delete/94530/spam Del: non-english -- https://master.php.net/note/delete/94530/non-english Del: in docs -- https://master.php.net/note/delete/94530/in+docs Del: other reasons-- https://master.php.net/note/delete/94530 Reject -- https://master.php.net/note/reject/94530 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162697) next »