简体   繁体   中英

Best way to start Laravel Artisan Command queue:work in Shared Hosting

I am trying for queue:work in Shared Hosting.

I went it with Cron Jobs, in every minute. But it is leading to Server Error after few hours the project started throwing Too many connections . Here is my Cron Job method

/usr/local/bin/php /home/username/public_html/system/artisan queue:work --timeout=60>> /dev/null 2>&1

Please, anyone, share which is the best practice for Starting Queue:Work, and I want it not to be shut down if it crashes or timeout, I want it to be restarted again.

By default, when the queue:work command finishes executing current tasks, it continues to wait for new work, and never exits. If you use it with the cron, it is not what you want.

You should use it with the --stop-when-empty option:

/usr/local/bin/php /home/username/public_html/system/artisan queue:work --stop-when-empty --timeout=60>> /dev/null 2>&1

Then the working thread will exit when there is no work left, and will be restarted by cron in a minute.

Without this option, a new thread is started every minute and keeps waiting for new work, but previous one does not exit, so you end up with a lot of threads holding connections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM