doudu4282 2017-03-20 15:19
浏览 142
已采纳

Laravel + Beanstalkd:如何运行“queue:listen”作为服务

I'm using Beanstalkd as a work queue in my project.

Now, my project is completed and I have to deploy it on VPS(production server).

There is something that confusing me! should I ssh to production server and manually type php artisan queue:listen ? (it's crap)

Is there any server to run queue:listen as service?

  • 写回答

1条回答 默认 最新

  • dounianluo0086 2017-03-20 15:39
    关注

    You should use something like Supervisor to run the queue in production. This will allow you to run the process in the background, specify the number of workers you want processing queued jobs and restart the queue should the process fail.

    As for the queue you choose to use, that's up to you. In the past I've used Beanstalkd locally installed on an instance and Amazon SQS. The local instance was fine for basic email sending and other async tasks, SQS was great for when the message volume was massive and needed to scale. There are other SaaS products too such as IronMQ, but the usual reason people run into issues in production are because they're not using Supervisor.

    You can install Supervisor with apt-get. The following configuration is a good place to start:

    [program:laravel-worker]
    process_name=%(program_name)s_%(process_num)02d
    command=php /home/forge/app.com/artisan queue:work --sleep=3 --tries=3
    autostart=true
    autorestart=true
    numprocs=8
    stdout_logfile=/home/user/app.com/worker.log
    

    This will do the following:

    • Give the queue worker a unique name
    • Run the php artisan queue:work command
    • Automatically start the queue worker on system restart and automatically restart the queue workers should they fail
    • Run the queue worker across eight processes (this can be increased or reduced depending on your needs)
    • Log any output to /home/user/app.com/worker.log

    To start Supervisor, you'd run the following (after re-reading the configuration/restarting):

    sudo supervisorctl start laravel-worker:*
    

    The documentation gives you some more in-depth information about using Supervisor to run Laravel's queue processes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分