我使用XMLParser和simplexml_load_dom时遇到问题。我试图在4中搜索每个文件2MB和27 MB文件。问题不在于内存,而在于执行时间(大约50秒)。我该如何优化代码?
public function searchInFeed()
{
$feed =& $this->getModel('feed','afiliereFeeduriModel');
$myfeeds = $feed->selectFeed();
foreach ($myfeeds as $f)
{
$x = new XMLReader();
$x->open($f->url);
$z = microtime(true);
$doc = new DOMDocument('1.0', 'UTF-8');
set_time_limit(0);
while ($x->read())
{
if ($x->nodeType === XMLReader::ELEMENT)
{
$nod = simplexml_import_dom($doc->importNode($x->expand(), true));
$data['text'] = 'Chicco termometru';
$data['titlu'] = 'title';
$data['nod'] = &$nod;
if ($this->searchInXML($data))
{
echo $nod->title."<br>";
}
$x->next();
}
}
}
echo microtime(true) - $z."<br>";
echo memory_get_usage()/1024/1024;
die();
}