In an effort to achieve efficiency, general functions and otuput input (I / O) is not directly
write data to a file, so we are instructed. There's also done is, to accumulate
to a new buffer and store (write) to disk in one time.
In order for a write operation directly implemented without in-pending advance, use the function
fflush (). Examples include the following:
$ Fp = fopen ('c: / tmp / test.txt', 'w');
fwrite ($ fp, 'Test flushing output');
/ / Flushing the output to a file
fflush ($ fp);
fclose ($ fp);
In some cases, there is the possibility of writing files that use fflush () result
failed to read the file. When a case like this happens to you, use the function clearstatcache ()
before you do the reading file contents.
Flushing Output to the Browser
Just as when doing flushing output to a file, you can perform flushing output to
browser. This technique can further improve the delivery of output to the browser. Implementation,
You should separate the fast processes and processes that require more time.
As an illustration, the preoperative data query is complete, you can send status information prior
first. Thus, the client does not find blank pages when the query is being performed.
A simple example like the following:
/ / Simulation user request
$ Keyword = 'Flushing Test';
$ Number = 1000;
echo 'Searching', $ keywords;
/ / Flushing the output to the browser
flush ();
echo '<p> Result: <br>';
/ / Simulation process large data
for ($ i = 1; $ i <$ Number, $ i + +) {
echo $ i, '', $ keywords, '<br>';
}
Function flush () will send all output-buffer internally in PHP to a web server.
In some cases, the client browser may not immediately display the data once it
obtainment. In addition, some versions of Internet Explorer will not display data until it
received at least 256 bytes of data. To solve this problem in Internet Explorer, you can
send character empty before flushing the output.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment