我从客户端(使用curl和自定义nodejs脚本测试)发送POST请求,没有正确回应响应。整个事情适用于PHP 5.6。
环境
整个事情尽可能地减少:
>一切运行在Vagrant VM Ubuntu 14.04 LTS
> nginx 1.9.7 from /packages/ubuntu/
> PHP7 FPM从官方来源编译–disable-all –enable-fpm
我使用的最小nginx网站配置:
server {
listen 80;
server_name localhost;
location / {
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_pass unix:/var/run/php/php7.0-fpm-api.sock;
fastcgi_param SCRIPT_FILENAME /vagrant/index.php;
}
}
来自/vagrant/index.php的PHP脚本示例:
echo str_repeat('.', 512);
flush(); // not necessary, only due testing
curl调用我使用:curl -XPOST http:// localhost / -H“传输编码:chunked”-d’
NodeJS脚本我使用:
'use strict';
var http = require('http');
var url = require('url');
var uri = url.parse(process.env.URL);
var options = {
method: 'POST', protocol: uri.protocol, hostname: uri.hostname,
port: uri.port, path: uri.path,
};
var data = '';
var httpRequest = http.request(options, function(res) {
res.on('data', function(chunk) {
console.log('received data', chunk.length);
data += chunk;
});
res.on('end', function() { console.log('final size', data.length); });
})
.on('error', function(err) { console.log(err); });
httpRequest.write('');
httpRequest.end();
将我的测试请求发送到PHP 5.6
$ curl http://localhost/
..........[cut off]
$ curl -XPOST http://localhost/ -H "Transfer-Encoding: chunked" -d ''
..........[cut off]
$ URL=http://localhost/ node php7test.js
received data 512
final size 512
将我的测试请求发送到PHP 7.0
$ curl http://localhost/
..........[cut off]
$ URL=http://localhost/ node php7test.js
final size 0
$ curl -XPOST http://localhost/ -H "Transfer-Encoding: chunked" -d ''
curl: (18) transfer closed with outstanding read data remaining
为什么我要分块编码?
没有商业理由这样做,但我使用非常类似的NodeJS代码,默认为分块编码,突然停止工作时切换到PHP7。
我发现以下工作从nodejs侧:显式设置Content-Length标头删除由NodeJS发送的隐式Transfer-Encoding:chunked头,因此适用于两个PHP版本。
但是我想了解为什么PHP7在这里行为不同,以及我是错误的还是这里真正发生了什么。
更新1:
>我比较了sapi / fpm /源5.6和7.0之间,几乎没有什么区别,我可以发现除了由于PHP内部的变化
>内置服务器(php -S)不受影响,所有测试
更新2:
我平分PHP源,并能够精确定位当行为改变:
在中间,从git bisect输出,提交我无法编译:
$ git bisect skip
There are only 'skip'ped commits left to test.
The first bad commit could be any of:
ba5ecf355fe792a5a2a8e6582d5e081d02b16fbf
e383cb4493031a7cd952cfcaed3297e583149c07
fef18f4bea1980a59a9283c2197bd090aaf500cb
18cf4e0a8a574034f60f4d123407c173e57e54ec
We cannot bisect more!