Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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