Home » Mail » Mail_Mbox » Bug #2566
_process() is extremely slow
Details
| 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) |
Comments
[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));
}
}