6

I have to run a laravel command php artisan queue:work --daemon to run jobs stored on Beanstalkd queues.

I have come across two possible solutions:

  • Run commands using Supervisord: Register a command in the config files of Supervisord and start it.
  • Run commands using CronJobs: */1 * * * * /usr/bin/php /var/www/laravelProj/artisan queue:work --daemon --tries=3

Can someone please explain what way should I go and what would be the best for performance enhancement.

Khuram
  • 1,820
  • 1
  • 26
  • 33

2 Answers2

9

There is one main advantage of Supervisor that the task you set there is working constantly. This mean that when the proces will finish the new one will starts immediately.

Crontab runs every process for a minutue minimum! So if you have a task like queue:work is much better to use Supervisor over Crontab.

Filip Koblański
  • 9,718
  • 4
  • 31
  • 36
2

Never Ever use CronJobs for this executing your queues. There are few differences between CronJobs and Superviser

  1. In CronJobs you have to set time for executing php artisan queue:work and lets suppose you set time for CronJob to run every 5 minutes then even if your current process is finished after 2 minutes, then the new process will start executing after 5 minutes because you set the time for cronjob to run after 5 minutes, but in Superviser when your current process is finished it will immediately start new process

  2. Second and most important reason why you shouldn't use cronjob for executing your queues is, It can suck all your memory and you will be seeing a lot of unwanted thing happening to your live site, because let's suppose you run a process which takes 5 minutes to execute and you set time for cronjob to run after 1 minutes then after every one minute it will execute command php aritisan queue:work. It won't wait to finish previous process and it will exhust all your resources, but in Superviser you can limit that how many process can run at a time and if processes reached to their limit Superviser will wait to finish previous processes

Ayyan Alvi
  • 759
  • 2
  • 9
  • 24