我遇到了一个奇怪的问题,我对下一步的调试感到困惑。我希望社区能提出一些想法。
我使用以下堆栈:
PHP 7.2.34-21+ubuntu16.04.1+deb.sury.org+1 (fpm-fcgi) (built: May 1 2021 11:52:36)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.34-21+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend TechnologiesServer version: Apache/2.4.39 (Ubuntu)Wordpress 4.9.16在AWS服务上。显然,由于框架存在一定的开销,但我可以将代码简化为如下内容:
// Framework stuff + file handling logic
$data = 'Imagine this is a 1000-byte binary message (pdf).';
// Headers, 335 bytes large
header('date: Sat, 03 Jul 2021 05:06:41 GMT');
header('server: Apache/2.4');
header('expires: Wed, 11 Jan 1984 05:00:00 GMT');
header('cache-control: no-cache, must-revalidate, max-age=0');
header('content-disposition: inline; filename=window-sticker.pdf');
header('strict-transport-security: max-age=1209600;');
header('content-length: 1000'); // Actually use strlen($data); for this
header('x-ua-compatible: IE=edge');
header('cache-control: public');
header('content-type: application/pdf');
echo $data;
exit();好了,好了,好了。这在许多其他站点上都很好,据我所知,使用相同的Apachesites-enabled配置和类似的.htaccess文件。但它可能仍然是一个服务器/网络/等等。输入错误所以我可能遗漏了什么。
但是,我有一个站点,其中的代码以以下方式中断:
不强制下载/显示instance).
content-length失败或抛出通知(safari,curl)的content-length,chrome表示)。卷发给我:* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7ff13c008200)
> GET /redacted/path/to/controller?p=abcdef HTTP/2
> Host: www.redacted-somesite.com
> User-Agent: curl/7.64.1
> Accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!
0 0 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0< HTTP/2 200
< date: Sun, 04 Jul 2021 17:36:24 GMT
< server: Apache/2.4
< expires: Wed, 11 Jan 1984 05:00:00 GMT
< cache-control: no-cache, must-revalidate, max-age=0
< content-disposition: inline; filename=window-sticker.pdf
< strict-transport-security: max-age=1209600;
< content-length: 1000
< x-ua-compatible: IE=edge
< cache-control: public
< content-type: application/pdf
<
* HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
* stopped the pause stream!
0 1000 0 0 0 0 0 0 --:--:-- 0:00:05 --:--:-- 0
* Connection #0 to host www.redacted-somesite.com left intact
curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
* Closing connection 0我检查过的东西:
内容长度file
e 224正在输出,因为像chrome这样的工具可以获得完整的 content-length头,这在所有工具中都可以实现。H 228f 229我们到了,我不知道为什么事情会失败。我目前的理论是,不知怎么的,对于这个站点来说,一些无声的错误可能是在发送头之前写入缓冲区的。但是当我用十六进制工具检查从服务器发送的二进制数据时,这是完全匹配的。所以我不知所措。也许有什么压缩层在耍我?
任何想法都会很棒。
谢谢!
发布于 2021-07-03 17:06:41
更新以匹配OP的最新编辑:
您提到的工具似乎不再使用HTTPV1.1协议,请参阅similar answer关于cURL的" HTTP /2流0没有完全关闭“的错误。
旧的答案:
内容长度应该与文件大小完全相同,但如果是的话,您可能遗漏了其他一些标题,例如:
Content-Transfer-Encoding: binary如果所有标头都在那里,请检查最大PHP执行。
https://stackoverflow.com/questions/68238120
复制相似问题