Home  >  Article  >  Backend Development  >  PHP nginx real-time output implementation method sharing

PHP nginx real-time output implementation method sharing

小云云
小云云Original
2018-01-24 11:25:131890browse

This article mainly introduces you to the simple implementation method of php nginx real-time output through example code. It is very good and has reference value. Friends who need it can refer to it. I hope it can help everyone.

The method to enable real-time output in PHP is ob_implicit_flush(), but it does not work in most cases because most of the output_buffering output buffering in the php.ini configuration is On, as well as zlib. output_compression is often turned on. In addition to the PHP layer, Nginx's buffering setting proxy_buffering and compression gzip are also mostly turned on. I'm afraid no one would 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 method to achieve instant output and real-time output content

php real-time output content

javascript realizes real-time output of the current time_javascript skills

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