php在迭代循环时回显结果
I am execution loop and inside loop there is data processing function inside loop.
for($i = 0 ; $i <=680 ; $i = $i + 40)
{
$url = 'http://www.yelp.com/biz/franchino-san-francisco?start=80';
$root = yelp($url);
var_dump($root);
}
This loop takes long time to execute, and results are echoed at the end when entire loop completes.
How can I echo the result during each iteration?
Actually what happens here? does to result are stored in buffer and at the end echoed or what?
我是执行循环和内部循环,循环内部有数据处理函数。 p>
此循环 需要很长时间才能执行,并且在整个循环完成时结果会在结束时回显。 p>
如何在每次迭代过程中回显结果? p>
实际上这里会发生什么? 结果是存储在缓冲区中,最后是回显还是什么? p>
div> for($ i = 0; $ i&lt; = 680; $ i = $ i + 40)
{
$ url ='http://www.yelp.com/biz/franchino- san-francisco?start = 80';
$ root = yelp($ url);
var_dump($ root);
}
code> pre>
PHP buffers the output.
If you want to output stuff to the browser immediately you can use the flush()
and ob_flush()
functions:
for ($i = 0; $i <= 680; $i += 40) {
$url = 'http://www.yelp.com/biz/franchino-san-francisco?start=80';
$root = yelp($url);
var_dump($root);
flush();
ob_flush();
}
If you are executing PHP through a web-page, this would be the behaviour.
PHP is a server side language and all code will be executed before displaying the output to the client. (using a browser)
If you want to display the result within the loop, better use console / cmd (command line)
Here is something that will help you use PHP with commandline.