2014-10-31 65 views
10

我最近我的生產服務器升級到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/"

read the documentation以及這個有點相關的問題:Undefined variable: HTTP_RAW_POST_DATA。但是,我無法弄清楚爲什麼會記錄此通知。據我所知,我沒有在我的代碼庫中的任何地方使用$HTTP_RAW_POST_DATA。我已經試過:

find . -exec grep "HTTP_RAW_POST_DATA" {} \; -print 2>/dev/null 

從我的項目(包括所有的供應商目錄)的根目錄下,但我沒有找到任何匹配。

I read more about always_populate_raw_post_data而且看起來$HTTP_RAW_POST_DATA只應在always_populate_raw_post_data參數設置爲TRUE時填充。我檢查了我phpinfo()和參數設置爲0。

如果我沒有明確調用$HTTP_RAW_POST_DATAalways_populate_raw_post_data設置爲0,爲什麼當我在我的錯誤日誌這些通知?什麼設置always_populate_raw_post_data-1呢?

+1

它可能被埋在服務器的配置文件中。 – 2014-10-31 16:25:13

+0

我想過這個。我運行了一個'find/etc/nginx -exec grep「always_populate_raw_post_data」{} \; -print 2>/dev/null',但沒有結果。另外,它在'phpinfo()'中顯示爲'0'。 – 2014-11-03 20:54:33

+0

你知道演習,創建最小的代碼來重現問題。 – 2014-11-06 21:25:34

回答

9

這裏是the relevant C code有我的評語:

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); 
} 

也就是說,設置always_populate_raw_post_data0仍然可以填充未知內容類型。你必須使用負值來完全跳過它。

這是現在在手冊中documented

用於訪問原始POST數據的優選方法是php://輸入,和$ HTTP_RAW_POST_DATA在PHP 5.6.0起已被棄用。將always_populate_raw_post_data設置爲-1將選擇將在將來版本的PHP中實現的新行爲,其中$ HTTP_RAW_POST_DATA從不定義。

+0

我發誓,關於將'auto_populate_raw_post_data'設置爲'-1'的提示不在昨天的文檔中! – 2014-11-06 22:30:19

+0

是的,它看起來像是爲了迴應所述的錯誤報告deW1而添加的註釋。 – georg 2014-11-06 22:37:27

+0

是的,它需要一段時間的文檔更新我猜,你沒有幸運檢查這1天后:) – deW1 2014-11-06 22:49:21

4

它已經被提交爲bug report

又讀this

基本上將值更改爲-1,這將解決您的「問題」。

還要確保您使用php://input閱讀更低於V

我認爲這將是更好的描述什麼是真正發生了: E_DEPRECATED將產生當$ HTTP_RAW_POST_DATA填充 其中由值控制always_populate_raw_post_data(鏈接 到http://php.net/manual/en/ini.core.php我們已經在 描述這種情況下,將$ HTTP_RAW_POST_DATA填充),並刪除 棄用的消息確保您不使用$ HTTP_RAW_POST_DATA 但是PHP://輸入,那麼你可以通過將always_populate_raw_post_data設置爲-1, 來禁用 $ HTTP_RAW_POST_DATA的填充,這將刪除E_DEPRECATED。

http://php.net/manual/en/ini.core.php

如果設置爲TRUE,PHP總會產生$ HTTP_RAW_POST_DATA 包含有原始的POST數據。否則,只有當數據的MIME類型無法識別時,變量纔會填充爲 。

訪問原始POST數據的首選方法是php://輸入,並且在PHP 5.6.0及之後的版本中不推薦使用$ HTTP_RAW_POST_DATA。將 always_populate_raw_post_data設置爲-1將選擇將在未來版本的PHP中實現的新行爲 ,其中 $ HTTP_RAW_POST_DATA從不定義。


更改PHP-5.6

可重複使用的,optioanlly JITty初始化PHP://輸入流變化 always_populate_raw_post_data INI設定接受三個值 ,而不是兩個。

-1:主人的行爲;永遠不要填充$ GLOBALS [HTTP_RAW_POST_DATA]

0 /關閉/不管:BC行爲(如果填充內容類型不是 註冊或請求方法是不同於POST)

1 /上/是/真:BC行爲(始終填充 $ GLOBALS [HTTP_RAW_POST_DATA])

+0

將值更改爲-1確實解決了問題。 – Morgan 2014-11-06 21:48:10