我有一个表用户需要连续上传,所以一旦更新,我想直接重新启动命令.
事实上,我使用的自行启动一个cron每分钟有Laravel( $schedule->command('update:users')->everyMinute();),但我失去了一些时间,如果工作是快超过一分钟,我会超载我的服务器如果超过一分钟.
我当时想要使用一个队列,一旦脚本终止,就会自行重启,如下所示:
// Do My stuff
Queue::push(new UpdateUsers($));
Run Code Online (Sandbox Code Playgroud)
但如果脚本崩溃,它将不会重新加载,我需要至少启动一次.我知道我可以使用pcntl_fork函数,但我想在Laravel上有一个交钥匙功能.我应该怎么做 ?
我建议在命令位置运行命令Cli
while (true)
Run Code Online (Sandbox Code Playgroud)
循环所以它将永远运行.创建此脚本后,您可以使用supervisord运行它
这个服务运行你告诉他的命令,当它失败时它将自动重新启动它.请注意,在X失败后它会停止,这取决于你如何配置它.
conf文件示例:
/etc/supervisord/conf.d/my_infinite_script.conf
Run Code Online (Sandbox Code Playgroud)
和内容可以是:
[program:laravel_queue]
command=php artisan your_command:here
directory=/path/to/laravel
autostart=true
autorestart=true
stderr_logfile=/var/log/your_command.err.log
stdout_logfile=/var/log/your_command.out.log
Run Code Online (Sandbox Code Playgroud)