Home  >  Article  >  Backend Development  >  PHP nginx real-time output example explanation

PHP nginx real-time output example explanation

小云云
小云云Original
2018-01-16 16:54:571895browse

This article mainly shares with you the explanation of php nginx real-time output examples, hoping to help everyone.

The method to enable real-time output in PHP is ob_implicit_flush(),

but it doesn’t work in most cases,

becausephp .iniIn the configurationoutput_bufferingmost of the output buffering is Onenabled,
and zlib.output_compressionis also often enabled,

In addition to the PHP layer, there are also Nginx buffering settings proxy_buffering, and compression gzip are also mostly enabled.
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').'
'; sleep(5); echo '五秒后:'.date('H:i:s');

Related recommendations:

PHP outputs messages to the browser in real time_PHP tutorial

PHP realizes instant output and real-time output content method

javascript realizes real-time output of the current time_javascript skills

The above is the detailed content of PHP nginx real-time output example explanation. 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