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

Bug #14574 bad memory usage of the _buildRequest method of Http_Request Class
Submitted: 2008-08-27 15:13 UTC
From: vincenta Assigned: avb
Status: Closed Package: HTTP_Request (version 1.4.3)
PHP Version: 5.2.6 OS: debian GNU/Linux
Roadmaps: 1.4.4    
Subscription  
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:
MUST BE VALID
Solve the problem : 20 - 15 = ?

 
 [2008-08-27 15:13 UTC] vincenta (Vincent Alquier)
Description: ------------ Sorry for bad english... If a file is uploaded using the Http_Request class, the _buildRequest function needs twice the file size of memory. As example when building the request to upload a 10 MB file, the function needs 20 MB of memory. In fact, the complete file is read into a $data var, then $data is copied into $postdata var (lines 973 to 984 of 1.4.3 stable release). Test script: --------------- I put echo of memory_get_usage() into the script code (lines 973 to 984). The output : before loading file : 6773128 Bytes after loading file : 15446868 Bytes after copying $data into $postdata : 24120464 Bytes The "test code" : foreach ($value['name'] as $key => $filename) { echo 'before loading file : '.memory_get_usage()." Bytes\n"; $fp = fopen($filename, 'r'); $data = fread($fp, filesize($filename)); fclose($fp); $basename = basename($filename); $type = is_array($value['type'])? @$value['type'][$key]: $value['type']; echo 'after loading file : '.memory_get_usage()." Bytes\n"; $postdata .= '--' . $boundary . "\r\n"; $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"'; $postdata .= "\r\nContent-Type: " . $type; $postdata .= "\r\n\r\n" . $data . "\r\n"; echo 'after copying $data into $postdata : '.memory_get_usage()." Bytes\n"; } Expected result: ---------------- Correct code : foreach ($value['name'] as $key => $filename) { $basename = basename($filename); $type = is_array($value['type'])? @$value['type'][$key]: $value['type']; $postdata .= '--' . $boundary . "\r\n"; $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"'; $postdata .= "\r\nContent-Type: " . $type; $fp = fopen($filename, 'r'); $postdata .= "\r\n\r\n" . fread($fp, filesize($filename)) . "\r\n"; fclose($fp); } Actual result: -------------- Actual code : foreach ($value['name'] as $key => $filename) { $fp = fopen($filename, 'r'); $data = fread($fp, filesize($filename)); fclose($fp); $basename = basename($filename); $type = is_array($value['type'])? @$value['type'][$key]: $value['type']; $postdata .= '--' . $boundary . "\r\n"; $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"'; $postdata .= "\r\nContent-Type: " . $type; $postdata .= "\r\n\r\n" . $data . "\r\n"; }

Comments

 [2008-09-11 14:49 UTC] vincenta (Vincent Alquier)
Is that Bug considered as irrelevant ? Is something missing in my bug report ?
 [2008-09-11 15:07 UTC] avb (Alexey Borzov)
Sorry for lack of attention, the patch looks good and I'll apply it in a few weeks time.
 [2008-10-09 10:27 UTC] avb (Alexey Borzov)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.