【发布时间】:2012-02-26 15:31:24
【问题描述】:
只是作为一个演示,试试下面的代码:
<?php
echo '<pre>';
ob_end_flush();
for($i=0;$i<2;$i++) {
passthru("ping -n 8 127.0.0.1");
@ob_flush();
}
echo '</pre>';
?>
这是输出:
Pinging stackoverflow.com [64.34.119.12] with 32 bytes of data:
Reply from 64.34.119.12: bytes=32 time=28ms TTL=56
Reply from 64.34.119.12: bytes=32 time=29ms TTL=56
Reply from 64.34.119.12: bytes=32 time=29ms TTL=56
Reply from 64.34.119.12: bytes=32 time=28ms TTL=56
Ping statistics for 64.34.119.12:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 28ms, Maximum = 29ms, Average = 28ms
Pinging stackoverflow.com [64.34.119.12] with 32 bytes of data:
Reply from 64.34.119.12: bytes=32 time=28ms TTL=56
Reply from 64.34.119.12: bytes=32 time=27ms TTL=56
Reply from 64.34.119.12: bytes=32 time=26ms TTL=56
Reply from 64.34.119.12: bytes=32 time=29ms TTL=56
Ping statistics for 64.34.119.12:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 26ms, Maximum = 29ms, Average = 27ms
它实际上做了两次(来自“小于 2”循环)。如果您测试脚本,您会注意到执行第一个脚本需要几秒钟,然后它会立即将其全部输出。之后(第二个循环)它逐行进行。我的目标只是有一个输出,逐行执行,而不是缓冲任何输出,如下所示,除非它发生:
<?php
system("ping -n 8 127.0.0.1");
?>
注意:这是在装有 PHP 5 的 Windows 服务器上运行的。
【问题讨论】:
-
我看不到您在哪里开始输出缓冲...?
-
我根本不想要输出缓冲。我发布的最后一个 PHP 代码块仅在命令完成后显示输出。同样的事情发生在 passthru 和 system 上。
标签: php windows cmd system buffer