Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.1

Request #15881 Stream access to body
Submitted: 2009-02-07 00:31 UTC
From: schmidt Assigned: avb
Status: Closed Package: HTTP_Request2
PHP Version: Irrelevant OS:
Roadmaps: 0.4.0    
Comments Add Comment Add patch

Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem : 50 - 27 = ?

 [2009-02-07 00:31 UTC] schmidt (Christian Schmidt)
Description: ------------ The current implementation stores the response body in a variable (contrary to the request body that may be consumed from a file). In order to download very big files (many gigabytes), it would be useful if the body could be read using a stream resource instead, i.e. like this: $response = $request->send(); $fp = $response->getBodyStream(); while (!feof($fp)) { $line = fgets($fp); // do stuff } fclose($fp); I'm afraid implementing this feature will require a rather big restructuring of the code. I would like to use this feature in the Services_Amazon_S3 package. Test script: --------------- Expected result: ---------------- Actual result: --------------


 [2009-02-07 12:30 UTC] doconnor (Daniel O'Connor)
Couldn't you simply implement a HTTP_Request2_Stream_Adapter which extends one of the other classes, and returns a HTTP_Request2_StreamResponse which implements your desired behaviour? IE; no need to rewrite huge chunks...
 [2009-02-08 01:20 UTC] avb (Alexey Borzov)
-Status: Open +Status: Verified -Assigned To: +Assigned To: avb -Roadmap Versions: +Roadmap Versions: 2.0.0beta1
Hmm, I now see that I forgot to port saveBody parameter from old HTTP_Request. You can use Observers now to save parts of the response body as it is being received, but the body is still saved in the property of the response object. Also it may be useful to limit the memory consumption even if not saving huge response bodies via Observers by using e.g. php://temp/ stream wrapper in HTTP_Request2_Response. Need to research further...
 [2009-04-04 02:41 UTC] avb (Alexey Borzov)
-Status: Verified +Status: Closed
Fixed in CVS: it is now possible to set 'store_body' config parameter to false to prevent keeping the whole body in a response object. Observers may be used to save parts of response body to disc while it is being received.