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

Bug #2566 _process() is extremely slow
Submitted: 2004-10-19 10:49 UTC
From: joern_h at gmx dot net Assigned: darkelder
Status: Closed Package: Mail_Mbox
PHP Version: 4.3.8 OS: Win 2000
Roadmaps: (Not assigned)    
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 : 44 + 16 = ?

 
 [2004-10-19 10:49 UTC] joern_h at gmx dot net
Description: ------------ _process() reads the mbox file character by character and is extremely slow. Loading a ~4MB file took about 20 seconds. I rewrote the _process() function to read the file linewise, after that change loading that file took about 1 second. The source code for the new function is attached. Reproduce code: --------------- function _process($resourceId) { $fp = $this->_resources[$resourceId]['fresource']; // sanity check if (!is_resource($fp)) { return PEAR::raiseError("Resource isn't valid."); } // going to start if (@fseek($fp) == -1) { return PEAR::raiseError("Cannot read mbox"); } $start = 0; $laststart = 0; while ($line = fgets($fp, 4096)) { if (0 === strncmp($line, 'From ', 5)) { $laststart = $start; $start = ftell($fp) - strlen($line); if ($start > 0) { $this->_resources[$resourceId]["messages"][] = array($laststart, $start-1); } } } if ($start > 0) { $this->_resources[$resourceId]["messages"][] = array($start, ftell($fp)); } }

Comments

 [2004-10-19 16:26 UTC] darkelder
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better. Thank you for your patch. Please note also that your it does handle messages if there is just one message on the file.
 [2004-10-20 05:41 UTC] darkelder
Please note that your patch does not work if there are only 1 mail on the file. I had to fix it. Thank you.