使用 PHP 和 Gearman 检测没有可用的服务器
我目前正在使用标准绑定将 Gearman 与 PHP 结合使用(此处的文档)。一切正常,但我有一个小问题,无法检测何时调用 GearmanClient::addServer (docs here) 是“成功”,我的意思是...
问题是添加服务器尝试不尝试任何套接字 I/O,这意味着服务器可能实际上不存在或无法运行。这意味着后续代码调用(在服务器实际上不存在的情况下)失败并导致 PHP 警告
有没有任何方法或最好的方法来确认 Gearman 守护进程在此之前或之后在服务器上运行添加它?
我想实现这一点,以便我可以可靠地处理 Gearman 可能已死亡或服务器无法联系的情况。
非常感谢。
I'm currently making use of Gearman with PHP using the standard bindings (docs here). All functioning fine, but I have one small issue with not being able to detect when a call to GearmanClient::addServer (docs here) is "successfull", by which I mean...
The issue is that adding the server attempts no socket I/O, meaning that the server may not actually exist or be operational. This means that subsequent code calls (in the scenario where the sever does not infact exist) fail and result in PHP warnings
Is there any way, or what is the best way, to confirm that the Gearman Daemon is operational on the server before or after adding it?
I would like to achieve this so that I can reliably handle scenarios in which Gearman may have died, or the server is un-contactable perhaps..
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们首先通过在主机上手动调用
fsockopen
并将端口传递给addServer
进行尝试,但事实证明,这可能会留下大量挂起的连接,因为 Gearman 服务器需要某些东西发生在该套接字上。我们使用监控脚本来检查守护进程及其工作人员的状态 - 类似于 Google 网上论坛上的这个 Perl 脚本。我们修改了脚本以在守护进程未运行时重新启动它。
如果这不吸引人,请查看 Gearman 协议(特别是“管理协议”部分,在上面的线程中引用)并使用
status
命令。这将为您提供有关作业和工作人员状态的信息,但也意味着您可以执行与守护程序的套接字连接,而不会使其挂起。We first tried this by manually calling
fsockopen
on the host and port passed toaddServer
, but it turns out that this can leave a lot of hanging connections as the Gearman server expects something to happen over that socket.We use a monitor script to check the status of the daemon and its workers — something similar to this perl script on Google Groups. We modified the script to restart the daemon if it was not running.
If this does not appeal, have a look at the Gearman Protocol (specifically the “Administrative Protocol” section, referenced in the above thread) and use the
status
command. This will give you information on the status of the jobs and workers, but also means you can perform a socket connection to the daemon and not leave it hanging.您可以使用此库:https://github.com/necromant2005/gearman-stats
它没有外部依赖性。
You can use this library: https://github.com/necromant2005/gearman-stats
It has no external dependencies.