Running an artisan command forever with laravel fo

2019-07-16 03:30发布

问题:

Can someone possibly advise how I can keep my custom artisan command running forever with the daemon?

I saw the many tutorials with queues, however it doesn't exactly fit. I am trying to accomplish "subscribe" with pubnub's php library and this seems like the best way, unless I missed something?

Thanks in advance!

回答1:

If you run the artisan command from the command line - it can already run indefinitely/forever. You dont need to do anything.

I have an application that has been running the one single artisan command for 97 days straight at the moment.

You then need to make sure it has not crashed for some reason, with something like Supervisor, or a web monitoring service like Eyewitness.io



回答2:

This will help you run artisan command forever

nohup php artisan yourcommand:abc > mylog.log 2>&1 & echo $! >> save_pid.txt

when you want to kill this process, get pid from save_pid.txt file

kill pid