Home  >  Article  >  Backend Development  >  About error handling after upgrading php7

About error handling after upgrading php7

藏色散人
藏色散人forward
2020-05-24 17:52:283835browse

Since the emergence of php7 has brought about significant performance improvements, I wanted to experience the features brought by the new version, so I upgraded.

Found that an error occurred when requesting the interface in the website, and recorded the solution after troubleshooting

After upgrading php, the site reported an error, the prompt is as follows:

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

After checking the php official website, we learned that some features have been abandoned in php5.6.X and later versions. For details, check:

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

The reason is:

$HTTP_RAW_POST_DATA 和 always_populate_raw_post_data

Using always_populate_raw_post_data will cause an E_DEPRECATED error when filling $HTTP_RAW_POST_DATA.

Please use php://input instead of $HTTP_RAW_POST_DATA as it may be removed in subsequent PHP versions.

Set always_populate_raw_post_data to -1 (this will force $HTTP_RAW_POST_DATA to be undefined, so it will not cause E_DEPRECATED errors) to experience the new behavior.

Repair method:

1. Modify the php configuration file and find php.ini. Turn on always_populate_raw_post_data and set it to -1.

always_populate_raw_post_data = -1

2. If $HTTP_RAW_POST_DATA is useful in the project, change it to:

It turns out to be $info = $HTTP_RAW_POST_DATA;

Change it to $info = file_get_contents( 'php://input');

Recommended: "PHP7"

The above is the detailed content of About error handling after upgrading php7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:mamicode. If there is any infringement, please contact admin@php.cn delete