如何使用 php 运行多个 beanstalk Worker
截至目前,我只为我的项目运行一个 beanstalk 工作线程,它处理基于 cron 的作业和实时作业。所以,我想把它分成两个工人。一名工作人员用于跟踪基于 cron 的作业,另一名工作人员用于跟踪实时异步作业。这样,工人的效率就会得到提高。任何人都可以帮助我解决这个问题,
- 如何使用 php 运行和取消多个 beanstalk 工作人员?
- 处理多个beanstalk工人的示例脚本?
注意:目前我正在使用 pheanstalk php lib。
As of now, I am running only one beanstalk worker thread for my project, which handles both cron based jobs and real time jobs. So, I want to separate it out into two workers. One worker is used to track the cron based jobs and one more to track the real time asynchronous jobs. So that, the worker efficiency will get improve. Anyone can help me on this,
- How to run and deamonize multiple beanstalk workers using php?
- A sample script to handle multiple beanstalk workers?
NOTE: Currently I am using pheanstalk php lib.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 pheanstalk(或其他库),如果您想从多个队列接受作业 - 只需观察它们即可。
至于处理工作人员,我目前正在使用 Supervisord 来处理一些我想继续运行的非常相似的脚本。它是一个基于 python 的守护进程,您想要运行的脚本列在一个非常简单的配置文件中。 (添加更多工作人员实际上就是更改单个数字,然后重新加载配置)。
我所做的一件事是基于博客文章 运行工人。 Supervisord 运行 shell 脚本。该脚本运行 PHP,PHP 又返回一个值(使用
exit($x)
)。如果我从队列运行程序返回一个值(例如)99,我就会退出 shell 脚本以关闭工作线程。另一个值可能会立即重新启动工作程序,其他任何值都会在重新启动之前休眠几秒钟。With pheanstalk, (or other libraries), if you want to accept jobs from a number of queues - just watch them.
As for handling workers, I'm currently using Supervisord for some very similar scripts that I want to keep running. Its a python based daemon where the script you want to run is listed in a very simple configuration file. (adding more workers is literally changing a single number, and reloading the configuration).
One thing I have done is based on the blog post running-the-worker. Supervisord runs a shell script. That script runs the PHP which in turn returns a value (with
exit($x)
). If I return a value from the queue-runner, (for example), 99, I quit the shell script to shut down the worker. Another value may instantly restart the worker, Anything else, sleeps for a few seconds, before it restarts.