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 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?