# RFC: Slim POST data

- Status: Implemented (PHP 5.6)
- Authors: Michael Wallner mike@php.net
- Date: 2013-12-17
- Version: 1.3
- Original: https://wiki.php.net/rfc/slim_post_data
- Page: https://externals.io/rfc/slim_post_data
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Votes

### RFC/slim_post_data (closed)

Yes: 17 · No: 0

Voters: aharvey (Yes), ajf (Yes), brianlmoon (Yes), datibbaw (Yes), derick (Yes), felipe (Yes), indeyets (Yes), joey (Yes), juliens (Yes), lstrojny (Yes), pajoye (Yes), philstu (Yes), thorstenr (Yes), tyrael (Yes), yohgaki (Yes), zhangzhenyu (Yes)

## Discussions on the mailing list

- [\[RFC\] Slim POST data (was: PHP-5.6 and $HTTP_RAW_POST_DATA)](https://externals.io/message/70198.md) — started on 2013-11-19, 32 messages
- [\[VOTE\] \[RFC\] Slim POST data](https://externals.io/message/70570.md) — started on 2013-12-10, 8 messages

---

## 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:

```php
$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:

```diff
@@ -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:

```shell
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](https://github.com/m6w6/php-src/compare/php:PHP-5.6...always_populate_raw_post_data)

## References

- [http://marc.info/?t=137760545600006&amp;r=1&amp;w=2](http://marc.info/?t=137760545600006&r=1&w=2)
- [http://marc.info/?l=php-internals&amp;m=138303606829213&amp;w=2](http://marc.info/?l=php-internals&m=138303606829213&w=2)
- [http://marc.info/?t=138449998700002&amp;r=1&amp;w=2](http://marc.info/?t=138449998700002&r=1&w=2)

## 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)
