Home > Backend Development > PHP7 > body text

About error handling after upgrading php7

藏色散人
Release: 2023-02-17 15:20:01
forward
3841 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:mamicode
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!