In the PHP program writing, the usage offlush () is still very high, it plays a very important role in the Web page performance of instant information, such as the previous written PHP implementation limit file download speed code instance , flush () Plays a pivotal role, is the key statement in the implementation code of the progress bar.
Explanation of Flash ()
Grammar:
Flush ();
Role:
Refreshes the PHP program's buffering, regardless of the circumstances in which PHP executes (CGI, Web server, etc.). This function sends all the output of the program so far to the user's browser.
Problem:
Flush () Refresh why can't I output buffering?
Very simple program code
for ($i =10; $i >2; $i--)
{
echo $i. ' <br/> ';
Flush ();
Sleep (1);
}
The result should be from 10 to 3, then output to the browser, as follows:
The above code, if there is no flush (), this sentence, 10 to 3 of the number will be output to the browser together.
However, this is the code above, I was successful in the local test, but uploaded into the space after the invalid, what is the matter?
Later I looked up the relevant information, found that flush (), the use of the need to pay attention to some problems, these problems may not be encountered when we do not think of it. That is, flush () needs to be used in conjunction with Ob_flush (), otherwise no buffering will be output in the Linux system.
and flush () and Ob_flush () with the use of the same time, the wording also need to pay attention to, that is to write Ob_flush (); write flush ();, as follows:
Ob_flush ();
Flush ();
Well, the symptom of the problem is here, so the above code should be written as follows:
for ($i =10; $i >2; $i--)
{
echo $i. ' <br/> ';
Ob_flush (); This sentence must not be less
Flush ();
Sleep (1);
}
Ob_end_flush ();
In this way, no matter which system, which Web server, can be the normal output buffering.
PHP flush () refresh cannot output buffering reason analysis