note 94531 added to function.getmypid
| From: | EricksonReyesercbluemonday at yahoo dot com | Date: | Tue, 10 Nov 2009 13:01:20 +0000 |
| Subject: | note 94531 added to function.getmypid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162698@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/94531
Del: integrated -- https://master.php.net/note/delete/94531/integrated
Del: useless -- https://master.php.net/note/delete/94531/useless
Del: bad code -- https://master.php.net/note/delete/94531/bad+code
Del: spam -- https://master.php.net/note/delete/94531/spam
Del: non-english -- https://master.php.net/note/delete/94531/non-english
Del: in docs -- https://master.php.net/note/delete/94531/in+docs
Del: other reasons-- https://master.php.net/note/delete/94531
Reject -- https://master.php.net/note/reject/94531
Search -- https://master.php.net/manage/user-notes.php