我最近将我的生产服务器升级到Ubuntu 14.04和PHP 5.6,现在我在错误日志中收到警告:
2014/10/31 10:42:45 [error] 17128#0: *46238 FastCGI sent in stderr: "PHP message: PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0" while reading response header from upstream, client: 24.123.216.42, server: example.com, request: "POST /api/notes HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "example.com", referrer: "https://example.com/admin/"
我阅读了文档以及这个有点相关的问题:未定义的变量:HTTP_RAW_POST_DATA.但是,我无法弄清楚为什么要记录此通知.据我所知,我没有$HTTP_RAW_POST_DATA在我的代码库中的任何地方使用.我试过了:
find . -exec grep "HTTP_RAW_POST_DATA" {} \; -print 2>/dev/null
Run Code Online (Sandbox Code Playgroud)
从我的项目的根目录(包括所有供应商目录),但我没有找到任何匹配.
我阅读了更多关于always_populate_raw_post_data,$HTTP_RAW_POST_DATA如果always_populate_raw_post_data参数设置为TRUE ,它似乎只应填充.我检查了我phpinfo()的参数设置为0.
如果我没有明确调用$HTTP_RAW_POST_DATA并always_populate_raw_post_data设置为0,为什么我会在错误日志中收到这些通知?什么是设置always_populate_raw_post_data到-1办?
这是与我的评论相关的C代码:
static zend_bool populate_raw_post_data(TSRMLS_D)
{
// not a post, empty request - return FALSE
if (!SG(request_info).request_body) {
return (zend_bool) 0;
}
// if always_populate_raw_post_data=0 then
// if we don't know how to parse the post (unknown mimetype) return TRUE
// otherwise (known mimetype) return FALSE
if (!PG(always_populate_raw_post_data)) {
return (zend_bool) !SG(request_info).post_entry;
}
// if always_populate_raw_post_data > 0 return TRUE
// if always_populate_raw_post_data < 0 return FALSE
return (zend_bool) (PG(always_populate_raw_post_data) > 0);
}
Run Code Online (Sandbox Code Playgroud)
也就是说,设置always_populate_raw_post_data到0仍能让填充未知的内容类型.您必须使用负值才能完全跳过它.
现在记录在手册中:
访问原始POST数据的首选方法是php:// input,并且在PHP 5.6.0以后不推荐使用$ HTTP_RAW_POST_DATA.将always_populate_raw_post_data设置为-1将选择将在未来版本的PHP中实现的新行为,其中永远不会定义$ HTTP_RAW_POST_DATA.