Gearman(使用 PHP)- 可以向所有工人发送作业/消息吗?
我是 Gearman 的新手,但我了解一般概念。我意识到这不是您通常想做的事情......但我想知道是否有办法向所有工人发送“工作”?
我有一个脚本可以监视我的工人并在他们死亡时重生他们。当我想杀死/重生所有工作进程时,我希望能够发送一个显示“死亡”的作业。
这可能吗?谢谢!
I'm new to Gearman, but I understand the general concepts. I realize that this isn't something that you would normally want to do... But I was wondering if there is a way to send a "job" to ALL workers?
I have a script that monitors my workers and respawns them when they die. I would like to be able to send out a job that says "die," when I want to kill / respawn all worker processes.
Is this possible? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法可以解决这个问题。
最简单的方法是为您拥有的每个工人发送“杀死”作业。当他们全部被杀死后,然后重生他们。这种方法的缺点是你必须等到所有工人都死了才能开始重生。如果您现有的脚本立即重生,您将在这里遇到问题。
另一种方法是为每个工人注册一个独特的任务。例如,如果您有两个工作人员,请为第一个工作人员注册任务“kill_001”,为第二个工作人员注册“kill_002”任务。要杀死你的工人,请确定要启动的独特作业(“kill_001”,“kill_002”),然后将其发送出去。重生的工作人员应该有新独特的任务,即如果新工作“kill_001”尚未被杀死,则不要注册它。尽管此方法可能需要更多工作,但它允许您在不停机的情况下重生您的工作人员。
There are a couple of ways that you can go about this.
The easiest way is to send the "kill" job for every worker that you have. Once they've all been killed, then respawn them. The downside of this method is that you will have to wait until all your workers are dead before you can begin respawning. If you existing script respawns immediately, you'll run into problems here.
Another method is to register a unique task for each of your workers. If, for example, you have two workers, register a task "kill_001" for the first worker, and "kill_002" for the second worker. To kill your workers, determine the unique jobs to start ("kill_001", "kill_002"), and then send them out. Respawned workers should have new unique tasks, i.e. don't register a new job "kill_001" if it hasn't been killed yet. Although this method can require a bit more work, it will allow you to respawn your workers without downtime.