升級php7後的報錯處理

來源:互聯網
上載者:User

標籤:stream   ann   提升   查詢   .net   未定義   tar   升級   效能   

*由於php7的出現帶來大幅的效能提升,想體驗下新版本帶來的特性,因此做了升級。
 發現在網站中請求介面時發生錯誤,排查後把解決方案記錄下來
  升級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

Warning: Cannot modify header information - headers already sent in Unknown on line 0

 

通過查詢php官網後得知,在php5.6.X以後版本某些特性已經被廢棄,詳情查看:

http://php.net/manual/zh/migration56.deprecated.php

 

原因是:
$HTTP_RAW_POST_DATA 和 always_populate_raw_post_data使用 always_populate_raw_post_data 會導致在填充 $HTTP_RAW_POST_DATA 時產生 E_DEPRECATED 錯誤。 請使用 php://input 替代 $HTTP_RAW_POST_DATA, 因為它可能在後續的 PHP 版本中被移除。 設定 always_populate_raw_post_data 為 -1 (這樣會強制 $HTTP_RAW_POST_DATA 未定義,所以也不回導致 E_DEPRECATED 的錯誤) 來體驗新的行為。

 

修複方法:

1、修改php的設定檔,找到php.ini。把 always_populate_raw_post_data 開啟,並設定為 -1 。

always_populate_raw_post_data = -1

 

2、如果項目中有用到$HTTP_RAW_POST_DATA的更改為:

原來是 $info = $HTTP_RAW_POST_DATA;更改為 $info = file_get_contents(‘php://input‘);

 

相關閱讀:$_POST、$HTTP_RAW_POST_DATA 和 php://input有什麼不同

升級php7後的報錯處理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.