Home >Backend Development >PHP Tutorial >Detailed explanation of the steps to achieve real-time output with php nginx

Detailed explanation of the steps to achieve real-time output with php nginx

php中世界最好的语言
php中世界最好的语言Original
2018-05-19 14:32:161608browse

This time I will bring you a detailed explanation of the steps for php nginx to implement real-time output. What are the precautions for php nginx to implement real-time output? The following is a practical case, let's take a look.

The method to enable real-time output in PHP is

ob_implicit_flush(),

but it doesn’t work in most cases,

because of the php.ini configuration Most of the output_buffering output buffering is turned on.

Also zlib.output_compression is often turned on.

In addition to the PHP layer, there is also Nginx's buffering setting proxy_buffering, and compression gzip is also mostly turned on.

I am afraid no one will make this choice to modify the website configuration of the entire server to meet the needs of one or two pages.

Here is a simple method recommended:

set_time_limit(0);
ob_end_clean();
ob_implicit_flush();
header('X-Accel-Buffering: no'); // 关键是加了这一行。
echo '现在是:'.date('H:i:s').'<br>';
sleep(5);
echo '五秒后:'.date('H:i:s');

Summary

I believe you have mastered the method after reading the case in this article. For more exciting content, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the algorithm steps to implement statistics on the number of 1's in a binary number

CI framework (CodeIgniter) Operation redis step analysis

The above is the detailed content of Detailed explanation of the steps to achieve real-time output with php nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn