Skip to content

Instantly share code, notes, and snippets.

@lighta971
Last active December 31, 2015 17:49
Show Gist options
  • Save lighta971/8022537 to your computer and use it in GitHub Desktop.
Save lighta971/8022537 to your computer and use it in GitHub Desktop.
<?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