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 .ini
In the configurationoutput_buffering
most of the output buffering is On
enabled,
and zlib.output_compression
is 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').'<br>'; 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!