我發現了一段代碼,顯示一個ping到通過PHP的服務器,我想知道是否有可能實現不同的輸出,但我在努力確定邏輯。邏輯的PHP和獲取第一個數組
代碼:
<?php
$cmd = "ping 8.8.8.8 -c 1";
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
flush();
$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./'), array());
echo "<pre>";
if (is_resource($process)) {
while ($s = fgets($pipes[1])) {
print $s;
}
}
echo "</pre>";
?>
電流輸出:
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=54 time=28.278 ms
--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 28.278/28.278/28.278 ms
通緝輸出:
我只希望MS值或 「時間」
個28.278
試驗:
我試圖抓住的「$s
」或「$pipes
」變量/陣列,包括通過以下運行它的數組值「[1]
」等的一些試驗的值代碼:
str_replace("time=","@@",$test_stringget_ping_res);
str_replace(" ms","@@",$test_stringget_ping_res);
但我得到「無法打開規則文件」。
所以,你只需要** **時間? – Rahul
@Rahul從第二行開始! – ReConnected