0
我有,我用它來在後臺運行PHP腳本文件PHP類,就像這樣:PHP後臺進程查殺本身
Class BackgroundScript{
public $win_path = "C:\\xampp\\htdocs\\www\\project";
public $unix_path = "/home/my_folder/project.com";
public $script = NULL;
public $command = NULL;
public $pid = NULL;
public $start_time = NULL;
public $estimated_time = NULL;
public $ellapsed_time = NULL;
public $status_file = NULL;
...
public function kill(){
$this->removeFile();
if (self::get_os() == "windows"){
shell_exec(" taskkill /PID ".$this->pid);
} else{
shell_exec('kill '.$this->pid);
}
}
}
這就是所謂的這種方式:
$argvs = " var1 var2 ";
$process = new BackgroundScript("controller.php processCSV $argvs");
然後,創建一個在後臺運行類似於此的代碼的過程:
$current_process = BackgroundProcess::getByPID(getmypid());
for ($=1; $i< 100; $i++){
performLongRunningTask();
$current_process->updateStatus();
}
我想知道的是,有可能在第e結束循環,下面的命令:
$process->kill();
考慮到這個php文件是由我要殺的進程執行的嗎?有什麼副作用我應該考慮?
你只是想停止一個PHP過程?這是否正在運行多線程? – 2014-09-22 17:29:00
嗯....我沒有準備好多線程的任何東西,但它應該能夠一次運行多個實例。我想知道的是,如果shell_exec('kill'。$ this-> pid)之後有任何代碼,會被執行,或者會立即停止。如果我不能更精確,我很抱歉,但是我對流程管理的知識非常薄弱,我不得不快速學習基本知識:P – sergio0983 2014-09-22 18:38:18