php 输出 继续执行,使用PHP中的实时输出运行进程
這是顯示shell命令的實(shí)時(shí)輸出的好方法:
header("Content-type: text/plain");
// tell php to automatically flush after every output
// including lines of output produced by shell commands
disable_ob();
$command = 'rsync -avz /your/directory1 /your/directory2';
system($command);
您將需要此功能來(lái)防止輸出緩沖:
function disable_ob() {
// Turn off output buffering
ini_set('output_buffering', 'off');
// Turn off PHP output compression
ini_set('zlib.output_compression', false);
// Implicitly flush the buffer(s)
ini_set('implicit_flush', true);
ob_implicit_flush(true);
// Clear, and turn off output buffering
while (ob_get_level() > 0) {
// Get the curent level
$level = ob_get_level();
// End the buffering
ob_end_clean();
// If the current level has not changed, abort
if (ob_get_level() == $level) break;
}
// Disable apache output buffering/compression
if (function_exists('apache_setenv')) {
apache_setenv('no-gzip', '1');
apache_setenv('dont-vary', '1');
}
}
它不適用于我嘗試過(guò)的每一臺(tái)服務(wù)器,我希望我可以提供一些關(guān)于你在php配置中尋找什么的建議,以確定你是否應(yīng)該試著讓你的頭發(fā)試圖讓這種行為發(fā)揮作用在你的服務(wù)器上!其他人都知道嗎?
這是普通PHP中的一個(gè)虛擬示例:
header("Content-type: text/plain");
disable_ob();
for($i=0;$i<10;$i++)
{
echo $i . "\n";
usleep(300000);
}
我希望這能幫助那些在谷歌上搜索的人。
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的php 输出 继续执行,使用PHP中的实时输出运行进程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: PhpStorm 配置debug断点调试
- 下一篇: ThinkPHP6项目基操(19.实战部