以å qiita ã§å ¬éãã¦ããè¨äºãå¼ã£è¶ãã¦ãããã®ã§ããæçµæ´æ°ããããªãçµã£ã¦ãããããæ å ±ã®æ£ç¢ºæ§ã¯è½ã¡ã¦ããå¯è½æ§ãããã¾ãã
Laravel ã® queue ã daemon ã§åããã«ã¯ããã£ã¦ã¿ã㨠Supervisor ã使ã£ã¦ããäºä¾ãå¤ãè¦ã¤ããã
ããããqueue:listen
(ã¾ã㯠queue:work --daemon
) ã pop ãã worker job ãå¦çãã¦ããæä¸ã§ããé æ
®ãªã SIG* ã§çµäºããã¦ãã¾ãå®è£
ã«ãªã£ã¦ããããã«è¦ãããããã¿ã¤ãã³ã°ã«ãã£ã¦ã¯ worker job ãé©åã«å®äºãããªãå ´åãããã
ã¡ãªã¿ã« Laravel ã® queue 㯠4.2 ã®å®è£ ã§ã¯ 2 種é¡åå¨ããã
- queue:listen 㯠pop ãã worker job ã Symfony/Component/Process/Process çµç±ã§ proc_open ããåããã»ã¹ã¨ãã¦å¦çããã
- queue:work --daemon ã¯èªèº«ã®ããã»ã¹å ã§é½åº¦ worker job ã pop ãã¦å®è¡ããã
ãã ããå¾è
㯠worker job ãçµäºããæ¯ã« queue:restart ã§çµäºå½ä»¤ãçºè¡ããã¦ããªãã確èªãã¦ãããã¦ããå ´å㯠queue:work --daemon
èªèº«ãçµäºããããã«ãªã£ã¦ããã
ãã㧠queue:restart
ã使ã£ã¦ãå®è¡ä¸ãããããªã worker job ã SIG* ã§å¼·å¶çµäºããããã¨ãªã queue:work --daemon
ãåèµ·åãããä»çµã¿ãèãã¦ã¿ãã
Laravel ã® Command ã® fire() ã§ä»¥ä¸ã®å®è£ ããã¦ã¿ãã
// start.php $pidFile = '/var/run/laravel-queue-work-daemon.pid'; if (File::exists($pidFile)) { return; } $pid = pcntl_fork(); if ($pid === -1) { exit(); } elseif ($pid !== 0) { exit(); } else { posix_setsid(); File::append($pidFile, posix_getpid() . PHP_EOL); $this->call('queue:work', [ '--daemon' => true ]); }
// stop.php
$pidFile = '/var/run/laravel-queue-work-daemon.pid';
if (! File::exists($pidFile)) {
return;
}
$pid = intval(File::get($pidFile));
$this->call('queue:restart');
$procPath = '/proc/' . $pid;
while (true) {
if (! File::exists($procPath)) {
break;
}
sleep(1);
}
File::delete($pidFile);
ãã㧠daemon ãèµ·åããæã¯
$ /usr/bin/nohup php artisan myqueue:start < /dev/null > /dev/null 2>&1 &
çµããããæã¯
$ php artisan myqueue:stop
ã¨ããããå ¥åããã°ããã