Linux の PHP 5.3 で php スクリプト (Jobque.php) をデーモン化したいと考えています。
アイデアは、次のようにスクリプトを呼び出すことです。
php -f ./application/Model/Jobque.php start
スクリプトが shell_exec を実行して自分自身をバックグラウンドに置き、このような処理を行うよりも
nohup php -f /var/.../application/Model/Jobque.php process 2> /dev/null & echo $!
この最後のコマンドは実際にバックグラウンドでスクリプトを開始し、すべて問題ありませんが、スクリプト自体からこのコマンドを発行すると、スクリプトは実行が停止するまで待機します (決して)
これは、スクリプトをデーモンとして開始するために使用する関数です-Windows部分は機能します
public function start_daemon() {
if (file_exists ( $this->pidfile ))
die ( 'process is already running - process pidfile already exists -> ' . $this->pidfile );
$cmd = 'php -f ' . __FILE__ . ' process';
if (substr ( php_uname (), 0, 7 ) == "Windows") {
$WshShell = new COM ( "WScript.Shell" );
$oExec = $WshShell->Run ( "$cmd /C dir /S %windir%", 0, false );
exec ( 'TASKLIST /NH /FO "CSV" /FI "imagename eq php.exe" /FI "cputime eq 00:00:00"', $output );
$output = explode ( '","', $output [0] );
$pid = $output [1];
file_put_contents ( $this->pidfile, $pid );
} else {
$execstr = "nohup $cmd 2> /dev/null & echo $!";
//echo $execstr; -- the execstr is right in itself
$PID = shell_exec ( $execstr );
//echo $PID; -- we never get here
file_put_contents ( $this->pidfile, $PID );
}
echo ('JobQue daemon started with pidfile:' . $this->pidfile);
}
ここで私は何を間違っていますか、そしてそれを正しく行う方法は?