【问题标题】:How to send HTTP/2 headers immediately when using PHP-FPM and Apache使用 PHP-FPM 和 Apache 时如何立即发送 HTTP/2 标头
【发布时间】:2019-08-18 22:48:03
【问题描述】:

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

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

我什至使用tcpdump -nn -i any -A -s 0 port 9000 查看了 TCP 连接流,我发现 PHP 直到最后才将标头发送到 Apache,所以问题出在 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: 标头在请求结束之前发送,即在 'test' 字符串之前发送,但事实并非如此。在5 秒延迟之后,所有标头都在请求结束时发送。

我做错了什么?

【问题讨论】:

  • 您可能正在寻找ob_flush
  • @Dave 它也不起作用。
  • 不知道为什么它不起作用,但有没有想过为此使用 103?
  • @BarryPollard PHP does not support 103 Early Hints, because it doesn’t have a native ability to send more than 1 status code back to a client - evertpot.com/http/103-early-hints

标签: php apache http-headers http2


【解决方案1】:

默认情况下,fastcgi_buffering 设置为 on

您需要在相关的location 块中添加:fastcgi_buffering off;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 2011-09-23
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    • 2015-07-29
    相关资源
    最近更新 更多