Urgent: questions about real-time PHP Data output to the client

Source: Internet
Author: User
Tags usleep
Urgent request: the test code for PHP real-time data output to the client is as follows: & lt ;? Phpob_start (); for ($ I = 1; $ I & lt; = 100; $ I ++) {& nbsp; $ sourceName = 'filetoupload '. $ I; & nbsp; urgent: questions about real-time PHP Data output to the client
The test code is as follows:
Ob_start ();
For ($ I = 1; $ I <= 100; $ I ++ ){
$ SourceName = 'filetoupload'. $ I;
$ ImageArray = array ();
$ Message = "Image $ I has been uploaded to the server ";
Echo $ message;
Flush ();
Ob_flush ();
Usleep (500000 );
}
Ob_end_flush ();
?>
The test results are as follows:
On the local server, the script can be run and output, but on the intranet server, the script is output after 100 cycles are run;

Expected results:
Like running results on a local server, the output is displayed while running. Why is the execution of the same script on an intranet server different? is it related to which configuration item in php. ini ??? Which configuration items are related ??? Thanks for your help.


------ Solution --------------------
If you are really anxious! I want to come up with a solution! That is, pass the value on the page. do not use a loop!
PHP code
$ Id = empty ($ _ GET ['id'])? 1: intval ($ _ GET ['id']); $ sourceName = 'filetoupload '. $ I; $ imageArray = array (); $ message = "Image $ I has been uploaded to the server"; echo $ message; if ($ id> = 100) {exit () ;}$ id ++; $ msg. ="
  "; Echo $ msg; exit ();
------ Solution --------------------
For this problem, I started linux for a long time and didn't use it. I finally found that it was a cache problem.
PHP code
    
------ Solution --------------------
Discussion
Reference:
For this problem, I started linux for a long time and didn't use it. I finally found that it was a cache problem.

PHP code

Ob_start ();
For ($ I = 1; $ I <= 100; $ I ++ ){
Ob_end_flush (); // disable caching
$ SourceName = 'filetoupload'. $ I;
$ ImageArray = arr ......

------ Solution --------------------
This buffer is related to the browser and some modules of apache.
Keep try
==========================================
PHP code
Ob_end_clean (); apache_setenv ('no-gzip ', 1); ini_set ('zlib. output_compression ', 0); ini_set ('implicit _ flush', 1); ob_start (); // start buffering data for ($ I = 1; $ I <= 100; $ I ++) {$ sourceName = 'filetoupload '. $ I; $ imageArray = array (); $ message = "Image $ I has been uploaded to the server
"; Echo $ message. str_repeat (" ", 1024); // ie has the default 1 k buffer ob_flush (); flush (); usleep (500000 );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.