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

PHP nginx real-time output example explanation

小云云
Release: 2023-03-19 14:52:01
Original
2043 people have browsed it

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').'<br>';
sleep(5);
echo '五秒后:'.date('H:i:s');
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template