I am facing a problem when a remote web client with slow connection fails to send complete POST request with multipart/form-data
content but PHP still uses partially received data to populate $_POST
array. As a result one value in $_POST
array can be incomplete and more values can be missing. I tried to ask same question in Apache list first and got an answer that Apache doesn't buffer the request body and passes it to PHP module as a
giant blob.
Here is my sample POST request:
POST /test.php HTTP/1.0
Connection: close
Content-Length: 10000
Content-Type: multipart/form-data; boundary=ABCDEF
--ABCDEF
Content-Disposition: form-data; name="a"
A
--ABCDEF
You can see that Content-Length
is 10000
bytes, but I send just one var a=A
.
The PHP script is:
<?php print_r($_REQUEST); ?>
Web server waits for about 10 seconds for the rest of my request (but I don't send anything) and then returns this response:
HTTP/1.1 200 OK
Date: Wed, 27 Nov 2013 19:42:20 GMT
Server: Apache/2.2.22 (Debian)
X-Powered-By: PHP/5.4.4-14+deb7u3
Vary: Accept-Encoding
Content-Length: 23
Connection: close
Content-Type: text/html
Array
(
[a] => A
)
So here is my question: How can I verify in PHP that the post request was received completely? $_SERVER['CONTENT_LENGTH']
would show 10000
from the request header, but is there a way to check the real content length received?