问题描述
这有点奇怪,尽管这会输出一个页面并部分显示,直到全部加载为止(类似于Wordpress更新/重新安装过程的工作原理):
Here's something odd, I though this would output a page and show part by part, until all is loaded (similar to how Wordpress update/reinstall process works):
<html>
<body>
<?php
for( $i=0; $i<100; $i++)
{
echo 'HELLO';
}
sleep(10);
echo '<p></p>';
for( $i=0; $i<100; $i++)
{
echo 'THERE';
}
sleep(10);
echo '<p></p>';
for( $i=0; $i<100; $i++)
{
echo 'HOW ';
}
sleep(10);
echo '<p></p>';
for( $i=0; $i<100; $i++)
{
echo 'ARE U';
}
sleep(10);
echo '<p></p>';
奇怪的是它等待整个页面,然后显示它.哪些变量/配置会影响此行为?
Oddly enough it waits for the entire page, then shows it. What variables/configuration affect this behavior?
推荐答案
我不知道您如何看待php的工作原理,但这只是服务器端,您希望在客户端进行部分更新.PHP不能那样工作.
I dont know how you think php works, but it is only server side and you are expecting partial updates in client side. PHP does not work like that.
当您调用该php脚本时,php解释器开始执行它,将输出放到临时位置,然后使用sleep函数,php解释器等待直到毫秒数,然后继续执行,将输出连接到temp位置,然后继续...完成所有脚本执行后,php将整个输出发送到客户端.
When you call that php script, php interpreter begin to execute it, putting the output into temporary location, then with the sleep function, php interpreter waits until milliseconds are reached, then continue executing, concatenating the output in the temp location, and go on... after all script execution is done, php sends the whole output to the client.
如果您需要在页面上进行部分更新,则需要输入异步调用和ajax的世界.
If you need partial updates on a page, you need to enter in the world of async calls and ajax.
这篇关于PHP何时不一次全部输出页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!