我想只在没有匹配的进程运行时才运行进程。这就是我所拥有的:
//get the processes that match artisan queue:work but not ps or grep processes
exec('ps -ef | grep "[a]rtisan queue:work"', $output);
//if no process if found start queue worker!
if(empty($output)) {
exec('/usr/local/bin/php /home/qwkhirec/laravel-dev/artisan queue:work --daemon');
}
当我在Laravel应用程序的测试端点上执行此操作时,代码可以正常工作。当我在Laravel调度程序上安排它时,它会在另一个之后创建一个进程。
几分钟后,我的机器每隔一分钟就会运行这些进程:
user 3128 2722 0 14:41 ? 00:00:00 /opt/cpanel/ea-php56/root/usr/bin/php /home/qwkhirec/laravel-dev/artisan queue:work --daemon
user 6347 6036 0 14:42 ? 00:00:00 /opt/cpanel/ea-php56/root/usr/bin/php /home/qwkhirec/laravel-dev/artisan queue:work --daemon
user 9896 9581 0 14:43 ? 00:00:00 /opt/cpanel/ea-php56/root/usr/bin/php /home/qwkhirec/laravel-dev/artisan queue:work --daemon
user 14095 13758 0 14:44 ? 00:00:00 /opt/cpanel/ea-php56/root/usr/bin/php /home/qwkhirec/laravel-dev/artisan queue:work --daemon
user 17921 17398 0 14:45 ? 00:00:00 /opt/cpanel/ea-php56/root/usr/bin/php /home/qwkhirec/laravel-dev/artisan queue:work --daemon
user 31538 30988 0 14:40 ? 00:00:00 /opt/cpanel/ea-php56/root/usr/bin/php /home/qwkhirec/laravel-dev/artisan queue:work --daemon