Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WAMP和flush()_Php_While Loop_Wamp - Fatal编程技术网

Php WAMP和flush()

Php WAMP和flush(),php,while-loop,wamp,Php,While Loop,Wamp,我试图通过让字符串迭代一定次数,在WAMP服务器上实现一个简单的while循环。但是,尽管在WAMP PHP设置中关闭了输出缓冲,但整个输出一次发生 版本1 $i = 0; while ($i < 5) { print ("This is an example of a while loop.<br/>"); flush(); sleep(1); $i++; } 版本2 $i = 0; while ($i < 5) { print ("This is an examp

我试图通过让字符串迭代一定次数,在WAMP服务器上实现一个简单的while循环。但是,尽管在WAMP PHP设置中关闭了输出缓冲,但整个输出一次发生

版本1

$i = 0;
while ($i < 5)
{
print ("This is an example of a while loop.<br/>");
flush();
sleep(1);
$i++;

}
版本2

$i = 0;
while ($i < 5)
{
print ("This is an example of a while loop.<br/>");
ob_start();
ob_flush();
flush();
sleep(1);
$i++;

}

这两个版本都没有按照我所希望的方式输出字符串,即每次一个,间隔一秒。非常感谢您的帮助。

我一直对WAMP和flush存在问题,最终得出结论,WAMP中的问题很简单。似乎无论我有什么服务器设置,WAMP的打包方式都有一些问题,那就是不起作用


让它工作的唯一方法是使用XAMPP,或者安装和配置您自己的服务器。

我遇到了这个问题,并通过合并以下代码位解决了这个问题

// Necessary Settings and stuff for output buffering to work right
apache_setenv('no-gzip', 1);
ini_set('zlib.output_compression', 0);
ini_set('implicit_flush', 1);
ini_set('output_buffering', "off");

// Start a new output buffer and send some blank data to trick browsers
ob_start();
echo str_repeat(" ", 4096);

for ($i=0; $i < 10; $i++) {
    echo "<div>Echo Something...</div>\n";

    // Call both ob_flush and flush functions
    ob_flush();
    flush();
}

对于那些即使有贾斯汀的解决方案也无法成功的人。在wamp x64上测试

// Necessary Settings and stuff for output buffering to work right
apache_setenv('no-gzip', 1);
ini_set('zlib.output_compression', 0);
ini_set('implicit_flush', 1);
ini_set('output_buffering', "off");

// Start a new output buffer and send some blank data to trick browsers
ob_start();
echo str_repeat(" ", 4096);
ob_end_flush(); //addition
ob_flush();
flush();

for ($i=0; $i < 10; $i++) {
    ob_start(); //addition
    echo "<div>Echo Something...</div>\n";

    ob_end_flush(); //addition
    ob_flush();
    flush();
}

何时渲染取决于浏览器…@dmubu阅读这里的描述,同时阅读:在关闭php.ini中的“输出缓冲”之前,我非常绝望。现在一切都和同花顺很好。