我試圖做一個應用程序,它會檢查它可以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