|
Posted by AviCoh on 12/15/06 18:25
Hi,
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
problems here).
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
user.
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.
Thx,
Avi
[Back to original message]
|