# [PATCH] Add option to disable POST data processing

- Thread: https://externals.io/message/50907
- Original archive: https://news-web.php.net/php.internals/50907
- Started by Patrick ALLAERT on 2010-12-07T23:53:32+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- 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

---

## #50907 — Patrick ALLAERT — 2010-12-07T23:53:32+00:00

URL: https://externals.io/message/50907#50907

It is not the goal to "block" but to prevent the usual processing of $_POST
when not required inside a valide POST request which will handle the input
differently.

Le 7 déc. 2010 23:36, "Tig" <tigger.on@gmail.com> a écrit :

If the objective is to 'block' POST data from getting to PHP, (in
apache) you can use:
http://httpd.apache.org/docs/2.0/mod/core.html#limit

No need to change / add anything to PHP.

-Tig


-- 

To unsubscribe, visit: http://www.php.net/...

---

## #50908 — Tjerk Meesters — 2010-12-08T00:45:56+00:00

URL: https://externals.io/message/50907#50908 · In reply to: #50907

Hi,

Don't have much knowledge about the internal workings of the engine, but I'm
wondering if it's possible to apply "lazy loading" to the $_POST variable,
so that processing only happens if and when it's requested.

That way you wouldn't need the ini setting.

> It is not the goal to "block" but to prevent the usual processing of
$_POST
> when not required inside a valide POST request which will handle the input
> differently.
>
> Le 7 déc. 2010 23:36, "Tig" <tigger.on@gmail.com> a écrit :
>
> If the objective is to 'block' POST data from getting to PHP, (in
> apache) you can use:
> http://httpd.apache.org/docs/2.0/mod/core.html#limit
>
> No need to change / add anything to PHP.
>
> -Tig
>
>
> --
> 
> To unsubscribe, visit: http://www.php.net/...

---

## #50909 — Gustavo Lopes — 2010-12-08T01:11:43+00:00

URL: https://externals.io/message/50907#50909 · In reply to: #50908

On Wed, 08 Dec 2010 00:45:56 -0000, Tjerk Meesters  
<tjerk.meesters@gmail.com> wrote:

> Don't have much knowledge about the internal workings of the engine, but  
> I'm wondering if it's possible to apply "lazy loading" to the $_POST  
> variable, so that processing only happens if and when it's requested.
>
> That way you wouldn't need the ini setting.

In most cases, processing (=parsing) of the POST data already only occurs  
when $_POST is requested; however, previously the data was already  
entirely copied to two or three memory locations.

If you mean making it so that the data is only *read and processed* when  
$_POST is requested, I suppose that would be possible, but I think it  
would require significant code/architectural changes to PHP and to the  
sapis. It would also raise other problems, including backwards  
compatibility breaks, if we wanted the change to bring any benefit.

For instance, current scripts can, in POST requests, read any number of  
times from php://input or $HTTP_RAW_POST_DATA (to simplify, let's say we  
even let go $HTTP_RAW_POST_DATA).  For this to be possible, you would have  
to have the data in memory because you're reading from php://input the  
first time, you can't know if it will be read a second time, so you either  
break BC or keep everything in memory just in case there's a second read  
-- and then you're where you started.

-- 
Gustavo Lopes

---

## #50912 — Clint Byrum — 2010-12-08T15:10:30+00:00

URL: https://externals.io/message/50907#50912 · In reply to: #50909

> On Wed, 08 Dec 2010 00:45:56 -0000, Tjerk Meesters  
> <tjerk.meesters@gmail.com> wrote:
> 
> > […]
> 
> In most cases, processing (=parsing) of the POST data already only occurs  
> when $_POST is requested; however, previously the data was already  
> entirely copied to two or three memory locations.
> 
> If you mean making it so that the data is only *read and processed* when  
> $_POST is requested, I suppose that would be possible, but I think it  
> would require significant code/architectural changes to PHP and to the  
> sapis. It would also raise other problems, including backwards  
> compatibility breaks, if we wanted the change to bring any benefit.
> 
> For instance, current scripts can, in POST requests, read any number of  
> times from php://input or $HTTP_RAW_POST_DATA (to simplify, let's say we  
> even let go $HTTP_RAW_POST_DATA).  For this to be possible, you would have  
> to have the data in memory because you're reading from php://input the  
> first time, you can't know if it will be read a second time, so you either  
> break BC or keep everything in memory just in case there's a second read  
> -- and then you're where you started.
> 

This example would be solved if during the lazy load you change the
php://input stream to point at the memory location that you read it
into.

---

## #50913 — Gustavo Lopes — 2010-12-08T18:49:16+00:00

URL: https://externals.io/message/50907#50913 · In reply to: #50912

> 
> > […]
>
> This example would be solved if during the lazy load you change the
> php://input stream to point at the memory location that you read it
> into.
>

I'm sorry, this doesn't make any sense. "The memory location you read  
into"? Who says you read the post data *into* something, much less a  
memory location?


-- 
Gustavo Lopes

---

## #50914 — Clint Byrum — 2010-12-08T19:13:08+00:00

URL: https://externals.io/message/50907#50914 · In reply to: #50913

> 
> 
> > […]
> 
> I'm sorry, this doesn't make any sense. "The memory location you read  
> into"? Who says you read the post data *into* something, much less a  
> memory location?
> 
> 

Sorry, to be more clear:

A lazy load on access to $_POST or $HTTP_RAW_POST_DATA would have to
read the POST data from the SAPI. At that point, the SAPI can keep the
buffer it allocates to read that data as a memory stream, and change its
notion of php://input to refer to that stream.

---

## #50915 — Gustavo Lopes — 2010-12-08T19:25:02+00:00

URL: https://externals.io/message/50907#50915 · In reply to: #50914

> 
> > […]
>
> Sorry, to be more clear:
>
> A lazy load on access to $_POST or $HTTP_RAW_POST_DATA would have to
> read the POST data from the SAPI. At that point, the SAPI can keep the
> buffer it allocates to read that data as a memory stream, and change its
> notion of php://input to refer to that stream.

What would be possible would be to consume all the data from a SAPI  
(typically indirectly from a socket, e.g. an Apache brigade), store it  
memory and make php://input read from there (i.e., the current behavior)  
but in a lazy manner when $_POST and $HTTP_RAW_POST_DATA are read.

However, this wouldn't solve the problem this option tries to resolve,  
i.e., avoid consuming the POST data into memory when all that's needed is  
a a stream-like access to that data (it also solves the problem the raw  
POST data is not available in multipart requests).

It wouldn't be solved because you would have to copy all the data into  
memory to permit multiple reads from php://input (the example I gave) and  
to allow reading from $_POST and php://input in the same request (for  
example, if you access $_POST first, you have to consume the whole POST  
data to build the array; at this point you will have needed to store this  
data somewhere to make it available to a subsequent read from php://input).

-- 
Gustavo Lopes
