Created
November 21, 2015 16:07
-
-
Save b4oshany/0fad2352b9284dcefc08 to your computer and use it in GitHub Desktop.
PHP subprocess
This file contains 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
<?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