PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Mail » Mail_Mbox » Bug #2566

_process() is extremely slow

Details

Submitted2004-10-19 10:49 UTC
Fromjoern_h at gmx dot net
Assigneddarkelder
StatusClosed
PackageMail_Mbox
PHP Version4.3.8
OSWin 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));
}
}