How to keep Laravel Queue system running on server

后端 未结 17 1039
小鲜肉
小鲜肉 2020-11-28 02:23

I recently setup a Laravel Queue system. The basics are a cronjob calls a command which adds jobs to a queue and calls a second command which sends an email.

The sy

17条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 03:13

    Running

    nohup php artisan queue:work --daemon &
    

    Will prevent the command exiting when you log out.

    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.

提交回复
热议问题