问题
I have implemented Laravel queue.The thing is i have to run the command php artisan queue:listen
every time.Is there any way that the jobs get executed automatically without running any command.
回答1:
Yes, if you use Linux you can use for example supervisor which will run php artisan queue:listen
(you need to add this command to supervisor configuration file) and it will make sure all the time this command is running.
回答2:
Here's a one-liner to put into your crontab (let it run, let say, every 5 minutes):
cd /path/to/your/project && jobs -l | grep `cat queue.pid` || { nohup /usr/bin/php artisan queue:listen & echo $! > queue.pid; }
two variables here:
1. /path/to/your/project
-- is your Laravel project root. Effectively, the folder, where php artisan
would work;
2. /usr/bin/php
-- path to PHP executable on the server (which php
)
来源:https://stackoverflow.com/questions/34513072/running-laravel-queues-automatically