Make WordPress Core

Opened 10 years ago

Closed 6 years ago

#31806 closed defect (bug) (invalid)

PHP Deprecated: $HTTP_RAW_POST_DATA

Reported by: jack772015's profile jack772015 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1.1
Component: REST API Keywords:
Focuses: Cc:

Description

Hi,

On PHP 5.6 the error_log for WordPress is giving this error:

[29-Mar-2015 20:04:43 UTC] 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

Change History (7)

#1 @SergeyBiryukov
10 years ago

  • Component changed from Posts, Post Types to General

#2 @jdgrimes
10 years ago

I've gotten this error occasionally on a site running PHP 5.6 as well.

This error actually has nothing to do with WordPress. Here is a good read on it:

tl;dr: ... Perfectly good code will spit out that error whenever it receives a request that has a (non-application/x-www-form-urlencoded encoded) payload. To fix it, explicitly set the value of always_populate_raw_post_data to -1 in your php.ini.

Note also that:

Unfortunately it’s not possible to override this value using ini_set ..., so one actually has to set it in php.ini.

So there is absolutely nothing that WordPress can do about this.

#3 follow-up: @dd32
10 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Since we don't require the presence of HTTP_RAW_POST_DATA (We already include back-compat, and now, forward-compat for it) and the warning can't be controlled by WordPress, there doesn't appear to be anything we can do about this.

For reference, the two locations using it are:

./src/wp-includes/class-IXR.php ~line 400
./src/xmlrpc.php ~line 20

#4 in reply to: ↑ 3 @jdgrimes
10 years ago

Replying to dd32:

For reference, the two locations using it are:

./src/wp-includes/class-IXR.php ~line 400
./src/xmlrpc.php ~line 20

Just a note for posterity: This error will occur regardless of whether HTTP_RAW_POST_DATA is actually used.

#5 @ocean90
9 years ago

#35583 was marked as a duplicate.

#6 @sc0ttkclark
6 years ago

  • Component changed from General to REST API
  • Resolution invalid deleted
  • Status changed from closed to reopened

Reopening this since it's referenced in WP_REST_Server::get_raw_data() as of WP 4.4. Still seeing this error sometimes happening, which WooCommerce may have found a way around it at one point with their legacy REST API endpoints using the following code above the $HTTP_RAW_POST_DATA usage:

<?php
// $HTTP_RAW_POST_DATA is deprecated on PHP 5.6.
if ( function_exists( 'phpversion' ) && version_compare( phpversion(), '5.6', '>=' ) ) {
        return file_get_contents( 'php://input' );
}

Should a similar fix be considered in core now that PHP 5.6+ is the requirement and this error will trigger on 5.6.x unless you are running 7.0+?

Asking because I'm seeing this crop up on certain sites which causes WP 5.x editor save failures (using default Gutenberg editor) with certain blocks that have more data to submit to the WP Posts REST API.

#7 @sc0ttkclark
6 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

Nevermind, rereading the ticket thread again and I was reminded that the error line is 0 and it can’t be related to the code usage in the REST API class. My bad. Unfortunate for those poor souls still running PHP 5.6

Note: See TracTickets for help on using tickets.