Take the State of PHP 2026 Survey →

Slim POST data View as Markdown

Implemented (PHP 5.6)
Authors
Michael Wallner mike@php.net
Date
2013-12-17
Version
1.3
Source
wiki.php.net/rfc/slim_post_data

Vote

RFC/slim_post_data closed
Yes
17
No
0
16 voters
aharvey Yes 2013-12-12 19:19
ajf Yes 2013-12-10 16:03
brianlmoon Yes 2013-12-10 16:09
datibbaw Yes 2013-12-16 09:07
derick Yes 2013-12-10 18:43
felipe Yes 2013-12-13 21:54
indeyets Yes 2013-12-10 16:55
joey Yes 2013-12-17 14:38
juliens Yes 2013-12-11 23:18
lstrojny Yes 2013-12-11 09:53
pajoye Yes 2013-12-11 05:48
philstu Yes 2013-12-11 18:11
thorstenr Yes 2013-12-14 18:56
tyrael Yes 2013-12-11 10:14
yohgaki Yes 2013-12-11 07:37
zhangzhenyu Yes 2013-12-17 09:11

Discussions on the mailing list

[RFC] Slim POST data (was: PHP-5.6 and $HTTP_RAW_POST_DATA)
by Michael Wallner · 32 messages
[VOTE] [RFC] Slim POST data
by Mike · 8 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:52 UTC

Introduction

A memory usage improvement regarding receiving HTTP payloads with a potential reduction of 200-300%.

Proposal

This change replaces the SAPI layer's (raw_)post_data entries with a temporary PHP stream.

If the request was a standard www-form-urlencoded or form-data POST, everything is just as it was before.

If the request had another request method or an unrecognized content type, the payload is available through the re-usable, just-in-time php://input stream.

Proposed PHP Version(s)

Next 5.x, i.e. 5.6

SAPIs Impacted

Web-SAPIs.

Unaffected PHP Functionality

Standard form POSTs and file uploads.

Changes to PHP-5.6

  • Re-usable, optioanlly JITty initialized php://input stream
  • Change always_populate_raw_post_data INI setting to accept three values instead of two.
    • -1: The behavior of master; don't ever populate $GLOBALS[HTTP_RAW_POST_DATA]
    • 0/off/whatever: BC behavior (populate if content-type is not registered or request method is other than POST)
    • 1/on/yes/true: BC behavior (always populate $GLOBALS[HTTP_RAW_POST_DATA])

Backward Incompatible Changes to master

$HTTP_RAW_POST_DATA and always_populate_raw_post_data were removed.

BC can be restored with:

$GLOBALS["HTTP_RAW_POST_DATA"] = file_get_contents("php://input");

Impact to Existing Extensions

Extensions utilizing SG(request_info).(raw_)post_data(_len).

In case of mbstring, the fix was as simple and ineffective as:

@@ -376,7 +377,10 @@ SAPI_POST_HANDLER_FUNC(php_mb_post_handler)
        info.num_from_encodings     = MBSTRG(http_input_list_size); 
        info.from_language          = MBSTRG(language);
 
-       detected = _php_mb_encoding_handler_ex(&info, arg, SG(request_info).post_data TSRMLS_CC);
+       php_stream_rewind(SG(request_info).request_body);
+       php_stream_copy_to_mem(SG(request_info).request_body, &post_data_str, PHP_STREAM_COPY_ALL, 0);
+       detected = _php_mb_encoding_handler_ex(&info, arg, post_data_str TSRMLS_CC);
+       STR_FREE(post_data_str);

Future Scope

The SAPI layer might be improved for SAPIs to provide their own PHP stream for POST data implementation, instead of soaking everything into the temp stream.

Proposed Voting Choices

  • Yes
  • No

Patches and Tests

To see the changes already in master, do, more or less:

git diff 1c15d70^..e6084da

http://git.php.net/?p=php-src.git;a=commitdiff;h=e6084da4735c945cb071c4d9259ea0d702eb77c6;hp=52ff129607a7193cccbc6bdfbf1c1e8586e8d0d2

Always_populate_raw_post_data patch is available here:

https://github.com/m6w6/php-src/compare/php:PHP-5.6...always_populate_raw_post_data

References

Changes

  • 1.1
    • Added PHP-5.6 patch to re-introduce always_populate_raw_post_data (-1/0/1)
  • 1.2
    • Re-ordered the RFC and reworded some sections.
  • 1.3
    • Accepted.

Vote

Vote: RFC/slim_post_data — Yes: 17 · No: 0 (closed)