Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- reading http request raw data as stream
December 15, 2006, 6:25 pm
rate this thread
Let me start with the question and then describe my case :
Is there a way to read the raw contents of an HTTP request in PHP as a
stream (i.e. not get it all at once from Apache) ?
In my case I am implementing an API for my server side app. One of the
actions in the API allows the posting of binary contents as
application/octet-stream. The size of this binary contents can get up
to several MBs.
I also employ a Basic HTTP authentication as part of the API, meaning,
that for every request I look for the authentication
headers(PHP_AUTH_USER and PHP_AUTH_PW). If the headers are missing (or
the credentials are not valid) I return "HTTP/1.0 401 Unauthorized" and
the client has to set the right headers and repost the request (no
This scenario is kinda problematic for me, as the authentication check
is only performed when the entire request is complete and reached PHP.
So posting 5MB would result in posting 10MB for an unauthenticated
Also, I use the nice stream wrapper 'php://input' in order to read the
posted binary contents, and again here I notice that the control is
passed to PHP only after the entire request had reached the server.
Any ideas on how to overcome this limitation ?
I'm using PHP 5.1 over Apache1.3 and Apache2.
- Janwillem Borleffs
December 17, 2006, 2:44 pm
Re: reading http request raw data as stream
However, I'm afraid it's not a viable (yet original :-D ) option for me
due to three reasons:
1. my hosting provider does not allow any incoming socket operations
(outgoing using curl via proxy only)
2. I wouldn't wanna go with any other port rather than 80 in order not
to have to deal with FW issues on the client side
3. I like what I get from Apache+PHP and wouldn't want to implement a
mini web server inside my app.
It just seems logical to me that PHP would support such a flow (like
perl or java for instance).
I have tried playing with some php.ini parameters :
changed the post_max_size to 0, and was able to receive the entire file
contents without having to wait for the request to finish.
The downside was that PHP kept screaming on that it had received a
request with a body bigger than the post_max_size....