PHP nginx Real-time output implementation method sharing

Source: Internet
Author: User
This article mainly through the example code to introduce the PHP nginx real-time output simple realization method, very good, has the reference value, needs the friend reference, hoped can help everybody.

The real-time output method in PHP is Ob_implicit_flush (), but it does not work in most cases because the output_buffering output buffers in the php.ini configuration are mostly on, and zlib.output_ Compression is also often opened, in addition to the PHP layer, there are Nginx buffer settings proxy_buffering, and compression gzip is mostly open. For the one or two page requirements, modify the entire server site configuration, I am afraid no one will make this choice.

Here's an easy way to do this:

Set_time_limit (0); Ob_end_clean (); Ob_implicit_flush (); header (' X-accel-buffering:no '); The key is to add this line. Echo ' is now: '. Date (' H:i:s '). ' <br> '; sleep (5); Echo ' Five seconds later: '. Date (' h:i:s ');

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.