PHP キュー システムを構築する必要がありましたが、このすばらしい記事
を見つけて、それを使用して PHP キュー システムを作成しました。セットアップと使用は非常に簡単です。http://squirrelshaterobots.com/programming/php/building-a-queue-server-in-php-part-1-understanding-the-project
以下は、シェル (puTTy など) から実行される queue.php のコードです。
<?PHP
//. set this constant to false if we ever need to debug
//. the application in a terminal.
define('QUEUESERVER_FORK', true);
//////// fork into a background process ////////
if(QUEUESERVER_FORK){
$pid = pcntl_fork();
if($pid === -1) die('error: unable to fork.');
else if($pid) exit(0);
posix_setsid();
sleep(1);
ob_start();
}
$queue = array();
//////// setup our named pipe ////////
$pipefile = '/tmp/queueserver-input';
if(file_exists($pipefile))
if(!unlink($pipefile))
die('unable to remove stale file');
umask(0);
if(!posix_mkfifo($pipefile, 0666))
die('unable to create named pipe');
$pipe = fopen($pipefile,'r+');
if(!$pipe) die('unable to open the named pipe');
stream_set_blocking($pipe, false);
//////// process the queue ////////
while(1){
while($input = trim(fgets($pipe))){
stream_set_blocking($pipe, false);
$queue[] = $input;
}
$job = current($queue);
$jobkey = key($queue);
if($job){
echo 'processing job ', $job, PHP_EOL;
process($job);
next($queue);
unset($job, $queue[$jobkey]);
}else{
echo 'no jobs to do - waiting...', PHP_EOL;
stream_set_blocking($pipe, true);
}
if(QUEUESERVER_FORK) ob_clean();
}
?>
最も困難な部分は、私のサーバーで pcntl 関数を動作させることでした。
私の質問は、「サーバーを再起動する必要がある場合にジョブを自動的に開始するにはどうすればよいですか?」です。
コメントで指摘されているように、壊れたリンクを編集し、後世のために優れた Web アーカイブを指摘しました。