我试图做一个应用程序,它会检查它可以ping外面,但它永远不会停止。我怎样才能将命令应用到终端并停止操作?实施例在以下情况下:如何使用system()或passthru()应用终端命令时停止PHP?
$ php -r "echo system('ping 127.0.0.1');"
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.073 ms
64 bytes from 127.0.0.1: icmp_req=2 ttl=64 time=0.073 ms
64 bytes from 127.0.0.1: icmp_req=3 ttl=64 time=0.072 ms
64 bytes from 127.0.0.1: icmp_req=4 ttl=64 time=0.074 ms
64 bytes from 127.0.0.1: icmp_req=5 ttl=64 time=0.071 ms
64 bytes from 127.0.0.1: icmp_req=6 ttl=64 time=0.073 ms
64 bytes from 127.0.0.1: icmp_req=7 ttl=64 time=0.074 ms
64 bytes from 127.0.0.1: icmp_req=8 ttl=64 time=0.073 ms
64 bytes from 127.0.0.1: icmp_req=9 ttl=64 time=0.074 ms
64 bytes from 127.0.0.1: icmp_req=10 ttl=64 time=0.081 ms
64 bytes from 127.0.0.1: icmp_req=11 ttl=64 time=0.072 ms
64 bytes from 127.0.0.1: icmp_req=12 ttl=64 time=0.075 ms
注:CTRL + C施加到停止但是这将通过Web浏览器来执行。
谢谢,我在Zend框架中看到他们也这样做:http://framework.zend.com/manual/en/zendx.console.process.unix.overview.html – YumYumYum 2011-05-29 18:25:09
什么是详细的向后方法,当你可以调用具有正确标志的子进程。 – 2011-05-29 18:56:14
@Tomalak 1)这个描述了一个通用的方法,它可以用于任何子进程而不仅仅是ping; 2)您可能需要在无限期的时间内运行ping,直到用户取消。 – Artefacto 2011-05-29 21:16:32