Is there a way to output the content in the cache immediately in the Nginx and php-fpm environments?

Source: Internet
Author: User
The following code is available: {code ...} according to the Code, it seems that every one second, when json data is output and nginx is used as the web server, the above Code is displayed, and php is output once after 10 seconds of running the program. output_buffering4096 in ini was later posted on the internet... the following code is available:

For ($ I = 1; $ I <= 10; $ I ++) {echo json_encode (array ('error' => 0, 'msg '=>' This is the test output --'. $ I); ob_flush (); flush (); sleep (1 );}

According to the Code, it seems that the json data is output every second.
When nginx is used as the web server, the above Code will be output once after 10 s of running the program.
Output_buffering = 4096 in php. ini
Later, I tried to use ob_end_clean (); ob_implicit_flush (true); these functions, but they still didn't work.

Reply content:

The following code is available:

For ($ I = 1; $ I <= 10; $ I ++) {echo json_encode (array ('error' => 0, 'msg '=>' This is the test output --'. $ I); ob_flush (); flush (); sleep (1 );}

According to the Code, it seems that the json data is output every second.
When nginx is used as the web server, the above Code will be output once after 10 s of running the program.
Output_buffering = 4096 in php. ini
Later, I tried to use ob_end_clean (); ob_implicit_flush (true); these functions, but they still didn't work.

flush();ob_flush();

WAMP:

For ($ I = 1; $ I <= 10; $ I ++) {echo str_pad ('', 4096); echo json_encode (array ('error' => 0, 'msg '=>' This is the test output --'. $ I); ob_flush (); flush (); sleep (1 );}

I tried it. This is acceptable.
Http://segmentfault.com/q/1010000000447596

Under Ngnix:
Disable zlib. output_compression = Off in php. ini.
Disable gzip off under nginx. conf
Modify the code to echo str_pad ('', 64000 );

function  test(){    header("Content-Encoding: none\r\n");    ini_set('zlib.output_compression', 'off');    ob_start();    for($i=0;$i<100;$i++){        echo str_repeat(" ",4096);        echo $i."
"; ob_flush(); flush(); sleep(1); }}

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.