Skip to content

Instantly share code, notes, and snippets.

@joshuapack
Created May 14, 2015 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuapack/ee54fd4b9418f140f6fa to your computer and use it in GitHub Desktop.
Save joshuapack/ee54fd4b9418f140f6fa to your computer and use it in GitHub Desktop.
PHP killing processes with a name
/*
This will kill all cpu processes launched by a certain php file. Can be used to kill other things too.
*/
$killTheseProcesses = "feednew.php";
$allProcesses = shell_exec("pgrep -lf php");
$allProcessesArray = explode("\n", $allProcesses);
array_pop($allProcessesArray);
foreach ($allProcessesArray as $process)
{
$processArray = explode(' ', $process);
if ($processArray[1] == 'php' && $processArray[3] > 0 && strpos($processArray[2],$killTheseProcesses) !== false) {
print $process."\n";
shell_exec("kill -KILL ".$processArray[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment