gpt4 book ai didi

php - 使用 PHP-FPM 和 Apache 时如何立即发送 HTTP/2 header

转载 作者:行者123 更新时间:2023-12-03 20:11:25 25 4
gpt4 key购买 nike

当以 FPM 运行时,我似乎无法立即从 PHP 发送 header 。它们仅在请求结束时与内容一起发送。

我有一个 Apache + PHP-FPM 设置。我在 PHP 和 Apache 中禁用了输出压缩。

我什至使用 tcpdump -nn -i any -A -s 0 port 9000 查看了 TCP 连接流,我发现 PHP 直到最后,所以问题出在 PHP 设置上。

请参阅下面我正在使用的测试代码。


header('Status: 200 OK');
header('Content-type: text/html; charset=utf-8');

header('Link: </src/app/src/App/Ui/Layout/default.css?__mtime=1553684041>; rel=preload; as=style;', false);

flush();

header('Test: 1', false);
sleep(5);
header('Test2: 2', false);

echo 'test';

我希望 Link: header 在请求结束之前发送,即在 'test' 字符串之前发送,但事实并非如此。在 5 秒延迟后,所有 header 都在请求结束时发送。

我做错了什么?

最佳答案

默认情况下 fastcgi_buffering 设置为 on

您需要添加:fastcgi_buffering off; 到相关的location block 。

关于php - 使用 PHP-FPM 和 Apache 时如何立即发送 HTTP/2 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55392956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com