Could you please share your best solution for run Laravel queue on production server?
For now I see next solution:
First start queue:
php artisan queue:work >> /var/log/queue.log &
Add to crontab:
10 2 * * * php artisan queue:restart
11 2 * * * php artisan queue:work >> /var/log/queue.log &
In case of project update on server:
php artisan down
php artisan queue:restart
#do update
php artisan queue:work >> /var/log/queue.log &
php artisan up
But I'm worrying about high load case. What if some job will be stucked?
Maybe you have better solution?
You can set up the laravel supervisor to run the queues automatically instead of using the cronjobs
Please find below the article for more details to run the queue automatically on the server without cronjob
Integration of Laravel Supervisor to process Queues
Related
My queue is working perfectly, when i run the following command php artisan queue:work
I’m using database as a QUEUE_DRIVER. On the server i don’t run the above command every-time.
for eg:
In schedule we have to run the command php artisan schedule:work. In this case on server we register this in cronetab like this:
* * * * * php /path/of/the/project/artisan schedule:run 1>> /dev/null 2>&1
Then we don’t have to run schedule work command again and again.
Is something also for queue. So we don’t have to run php artisan queue:work again and again. Also i don’t want to change the driver.
In my application, every customer has a kind of complex class in which we do some search and replaces for that specific customer. I run Queue workers to run a daily sync with eBay for every single customer to do some kind of search and replaces.
The problem is Laravel queues caches the code for a good deal of time and if I want to go and change any customer class file (Which happens frequently), I will have to restart queue workers (Which may stop a running job that I don't intend to stop).
So my question is, how to force Laravel Queue to reread the new code without restarting workers?
you will have not cache if you use code:
php artisan queue:listen
Also, interest command:
php artisan queue:work --queue=system,hot,default --tries=10 --timeout=10 --stop-when-empty
Open an extra terminal and use the artisan command
php artisan queue:restart
This command will instruct all queue workers to gracefully "die" after they finish processing their current job so that no existing jobs are lost.
You may gracefully restart all of the workers by issuing the queue:restart command:
php artisan queue:restart
source: https://laravel.com/docs/5.8/queues#running-the-queue-worker
so the full chain of commands should be (maybe) this:
composer dump-autoload
php artisan optimize
php artisan clear-compiled
php artisan cache:clear
php artisan view:clear
php artisan route:cache
php artisan queue:restart
I left out the config cache command on purpose because I don't want to run it initially. Running it, will actually start to cache your config file afaik so I dont want that.
I'm answering because I want to store my own answer to evernote, to never ever have to deal with that bs again
In my table "jobs" have 5 jobs, i used the process "php artisan queue:listen" on localhost then it ran all jobs and finished. But when i used this process on server then it only once ran one jobs (same "php artisan queue:work"). I use queue_driver is "database".
Update - Laravel 5.5+
Just use:
php artisan queue:work --once
TL;DR
php artisan queue:work = run one queued job and stop
php artisan queue:listen = run all queued jobs and listen for more until stopped
Further detail:
How are you running the commands? Are you just opening a terminal and running it or do you have a cron job to run at intervals?
If you're just opening a terminal and running php artisan queue:work will complete one task on the queue then stop, whereas if you run php artisan queue:listen it will process all the jobs in the queue and continue to listen for any further jobs until it is stopped.
Read further in the docs regarding queue:work:
Starting The Queue Listener
Laravel includes an Artisan command that will run new jobs as they are
pushed onto the queue. You may run the listener using the queue:listen
command:
php artisan queue:listen
Processing The First Job On The Queue
To process only the first job on the queue, you may use the queue:work command:
php artisan queue:work
What you should be doing?
I am guessing what you ideally want to do on your server is set up a cron job to run continuously at intervals and have it run queue:work. Better yet, acquaint yourself with the docs and make a decision after that.
See similar question answered here: What is the difference between queue:work --daemon and queue:listen
I actually have a mailing system that I want to implement using queues in Laravel. Every time an order is placed, the customer should receive a mail.
I used
Mail::queue('mail.view',$data,function($message){
$message->to($email,$name)->subject('Order Confirmed.');
}
Then, I run php artisan queue:work to actually process the queue. How can I automate the work?
I'm using Openshift for hosting.
According to Laravel Coding, a way of doing this is
One is load up artisan queue:listen in the startup scripts of your server. This command automatically calls artisan queue:work when items appear in the queue.
How do I add artisan queue:listen to startup scripts?
Assuming you're using the OpenShift Laravel 5 QuickStart...
After line #91 in the .openshift/action_hooks/deploy file, add a call to artisan queue:listen:
php artisan migrate --force
php artisan queue:listen
Does self-hosted (non-Forge) Laravel have a cron system? Or has this been supplanted by worker queues?
That is, in many PHP frameworks, there's a single cron file to run -- often named cron.php. You're usually instructed to configure this script to run every 15 minutes (or some similar time) via a unix cron job.
1,15,30,45 * * * * /path/to/php /path/to/cron.php
Does Laravel have a similar system? Googling about I've seen some mentions that Forge has a solution for this, and that older version of Laravel might have had a system, but I haven't been able to find a clear answer W/R/T Laravel 4.
You can schedule artisan commands and make your own commands like so:
php artisan command:make cronCommand
Which will result in a cronCommand.php file in your app/commands directory
Then you make artisan aware of the command
Add Artisan::add(new cronCommand); to app/start/artisan.php
composer dump-autoload
Now you can see your new command via php artisan list
and schedule it via 1,15,30,45 * * * * artisan cronCommand
Reference
Laravel Commands - Documentation
Taylor Otwell - Building Artisan Commands
Dispatcher - Artisan Command Scheduler