0

我正在使用Simple HTML Dom。我正在尝试运行以下命令:(使用 WAMP)

$doc = file_get_html('http://www.scoop.it/t/curate-your-personal-learning-environment?page=3');
$comments = array();
$CommentList = $doc->find('#commentList div[class=commentContainer]');
if (count($CommentList) > 0)
    var_dump($CommentList);
foreach ($CommentList as $comment)
{
    $text = $comment->find('span[class^=author]');
    $comments[] = $this::ctrim($text[0]->innertext);
}

如果我注释掉 foreach 循环,它运行良好。否则,apache 崩溃。

一个重要的注意事项:如果我注释掉 foreach 循环的内部,它仍然会崩溃。我添加了 var 转储以确保数组具有有效项目。

编辑:

阿帕奇日志:

[Tue Jul 10 16:53:53 2012] [notice] Parent: child process exited with status 255 -- Restarting.
[Tue Jul 10 16:53:53 2012] [notice] Apache/2.2.22 (Win64) PHP/5.3.13 configured -- resuming normal operations
[Tue Jul 10 16:53:53 2012] [notice] Server built: May 13 2012 19:41:17
[Tue Jul 10 16:53:53 2012] [notice] Parent: Created child process 5568
[Tue Jul 10 16:53:53 2012] [notice] Child 5568: Child process is running
[Tue Jul 10 16:53:53 2012] [notice] Child 5568: Acquired the start mutex.
[Tue Jul 10 16:53:53 2012] [notice] Child 5568: Starting 64 worker threads.
[Tue Jul 10 16:53:53 2012] [notice] Child 5568: Starting thread to listen on port 80.
[Tue Jul 10 16:53:53 2012] [notice] Child 5568: Starting thread to listen on port 80.
4

2 回答 2

2

这可能是内存泄漏:
因为您的 apache 说:

子进程以状态 255 退出

请参见此处:
PHP 内存不足 - 使 Apache 崩溃?

由于 php5 循环引用内存泄漏,创建 DOM 对象后,如果多次调用 file_get_dom() 必须调用 $dom->clear() 释放内存。

从这里:http ://simplehtmldom.sourceforge.net/manual_faq.htm#memory_leak

于 2012-07-10T14:05:04.310 回答
1

尝试改变

$this::ctrim($text[0]->innertext);

self::ctrim($text[0]->innertext);

或者

$this->ctrim($text[0]->innertext);

$obj->method是一个实例调用。 Class::method是静态调用。 $this::method可能会做一些奇怪的事情......

于 2012-07-10T12:42:06.933 回答