Last active
December 31, 2015 17:49
-
-
Save lighta971/8022537 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* Thanks to Erickson Reyes ercbluemonday at yahoo dot com | so processes dont overlap | |
* ref : http://www.php.net/manual/en/function.getmypid.php#94531*/ | |
// 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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment