Created
May 14, 2015 14:33
-
-
Save joshuapack/ee54fd4b9418f140f6fa to your computer and use it in GitHub Desktop.
PHP killing processes with a name
This file contains hidden or 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
/* | |
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