3

In my project I am using database queue and executing this queue by using command

php artisan queue:listen

in composer and it is working. But in my windows server, there are many projects that using queues so many windows of composer are open. It is quite inconvenient. Is this possible to run this command in background without composer window open?

manoos
  • 1,675
  • 3
  • 21
  • 46

1 Answers1

1

YOu can use the command but it will work only until you logout or restart

nohup php artisan queue:work --daemon &

The trailing ampersand (&) causes process start in the background, so you can continue to use the shell and do not have to wait until the script is finished.

See nohup

nohup - run a command immune to hangups, with output to a non-tty

This will output information to a file entitled nohup.out in the directory where you run the command. If you have no interest in the output you can redirect stdout and stderr to /dev/null, or similarly you could output it into your normal laravel log. For example

nohup php artisan queue:work --daemon > /dev/null 2>&1 &

nohup php artisan queue:work --daemon > app/storage/logs/laravel.log &

But you should also use something like Supervisord to ensure that the service remains running and is restarted after crashes/failures.

Running queue:listen with supervisord

supervisord is a *nix utility to monitor and control processes below is a portion of /etc/supervisord.conf that works well.

Portion of supervisord.conf for queue:listen

[program:l5beauty-queue-listen]
command=php /PATH/TO/l5beauty/artisan queue:listen
user=NONROOT-USER
process_name=%(program_name)s_%(process_num)d
directory=/PATH/TO/l5beauty
stdout_logfile=/PATH/TO/l5beauty/storage/logs/supervisord.log
redirect_stderr=true
numprocs=1

You’ll need to replace the /PATH/TO/ to match your local install. Likewise, the user setting will be unique to your installation.

Prashant Barve
  • 4,105
  • 2
  • 33
  • 42