惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
Cyberwarzone
Cyberwarzone
D
Docker
The Hacker News
The Hacker News
C
CERT Recently Published Vulnerability Notes
Vercel News
Vercel News
Project Zero
Project Zero
S
Schneier on Security
aimingoo的专栏
aimingoo的专栏
I
Intezer
腾讯CDC
M
MIT News - Artificial intelligence
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
GbyAI
GbyAI
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Vulnerabilities – Threatpost
G
Google Developers Blog
N
Netflix TechBlog - Medium
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
A
Arctic Wolf
S
Securelist
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
Recent Announcements
Recent Announcements
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 热门话题
T
Threatpost
Latest news
Latest news
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
The GitHub Blog
The GitHub Blog
T
Tor Project blog
P
Proofpoint News Feed

小锋博客

mac无法删除软件,提示已锁定的解决方法-小锋博客 php的ob系列函数中flush()与ob_flush()的区别-小锋博客 php中strpos字符串函数用法详解-小锋博客 2023-11-23-小锋博客 2023-09-24-小锋博客 2022.02.01-小锋博客 2020.08.23-小锋博客 2020.04.06-小锋博客 2020.02.14-小锋博客
nginx服务器中ob_flush函数和flush函数不起作用的解决方案-小锋博客
XiaoFeng · 2023-12-03 · via 小锋博客

做一个逐行输出的功能,使用ob_flush时试了N种方法不起作用,比如下面的代码:

ob_start();
for(;;)
{
    echo ".......";
    ob_flush();
    flush();
    sleep(1);
}

谷歌了不少的写法都不行,所以问题应该出在了环境配置上而不是使用方法上。

话说还是stackoverflow给力,搜索“php flush not working”找到了一个正确的解决方法:

检查nginx配置文件(nginx.conf),禁用nginxbuffering

proxy_buffering off;
gzip off;
fastcgi_keep_conn on;

要注意最后这句fastcgi的哦~~

检查php.ini,禁用buffering

output_buffering = off

注意这句配置不能通过ini_set()函数动态在程序中设置,这在php官方手册中有说明:

the output_buffering setting is PHP_INI_PERDIR therefore it may not be set using ini_set()

经过上面两步的配置(nginx.confphp.ini)后,重启nginx就可以了,再次测试文章开头的代码,成功逐行输出。