ping 客户端的最佳方法
是的,我有一个 PHP 脚本正在工作,其中服务器 ping 是客户端。我面临的问题是,有时服务器无法联系客户端,尽管当我手动 ping 客户端时,它可以成功 ping 通。
我使用的 ping 命令是 ping -q -w 3 -c 1
ipaddresshere >
ping 客户端的最佳方式是什么,如果 ping 在某个时间之前失败,可能会2/3 次,留下2/3 秒的间隙重试?
Right, I have a PHP script at work where the server ping's a client. The problem I am facing is that sometimes the server cannot contact the client although when I manually ping the client it ping's successfully.
The ping command I am using is this ping -q -w 3 -c 1 < ipaddresshere >
What would be the best way of pinging the clients maybe 2/3 times leaving like a 2/3 second gap if a ping fails before a retry?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您在 Unix 环境中时,您始终可以创建然后调用 shell 脚本来处理循环和等待。但令我惊讶的是你不能在 php 内部做到这一点。
另外,我不确定你的示例 ping 命令,我检查的 2 个不同环境似乎对你提到的选项有不同的含义,而不是你想要的。尝试
man ping
或ping --help
下面的脚本应该为您提供一个用于实现 ping 重试的框架,但我不能在上面花费大量时间。
我希望这有帮助。
PS,由于您似乎是新用户,如果您得到的答案对您有帮助,请记住将其标记为已接受,和/或给它 +(或 -)作为有用的答案。
As you are in the unix environment, you can always make and then call a shell script to handle the looping and waiting. But I'm surprised that you can't do that inside of php.
Also, i'm not sure about your sample ping command, the 2 different environments I checked seem to have different meanings for the options you mention than what you seem to intend. Try
man ping
ORping --help
The script below should give you a framework for implementing a ping-retry, but I can't spend a lot of time on it.
I hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.
对于 php,您可以尝试 PEAR 的 Net_PING 包。
这是一个指导您完成此操作的链接
http://www.codediesel.com/php/ping-a-服务器使用-php/
for php, you can try PEAR's Net_PING package.
here is a link guiding you through it
http://www.codediesel.com/php/ping-a-server-using-php/