Skip to content

Instantly share code, notes, and snippets.

@b4oshany
Created November 21, 2015 16:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b4oshany/0fad2352b9284dcefc08 to your computer and use it in GitHub Desktop.
Save b4oshany/0fad2352b9284dcefc08 to your computer and use it in GitHub Desktop.
PHP subprocess
<?php
/**
* @author Ashraf M Kaabi
* @name Advance Linux Exec
*/
class Process {
/**
* Run Application in background
*
* @param unknown_type $Command
* @param unknown_type $Priority
* @return PID
*/
function background($Command, $Priority = 0){
if($Priority)
$PID = shell_exec("nohup nice -n $Priority $Command > /dev/null & echo $!");
else
$PID = shell_exec("nohup $Command > /dev/null & echo $!");
echo $PID;
return($PID);
}
/**
* Check if the Application running !
*
* @param unknown_type $PID
* @return boolen
*/
static function is_running($PID){
exec("ps $PID", $ProcessState);
return(count($ProcessState) >= 2);
}
/**
* Kill Application PID
*
* @param unknown_type $PID
* @return boolen
*/
static function kill($PID){
if(exec::is_running($PID)){
exec("kill -KILL $PID");
return true;
}else return false;
}
};
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment