【问题标题】:PHP simple html dom: apache crashesPHP简单的html dom:apache崩溃
【发布时间】:2012-07-10 12:32:02
【问题描述】:

我正在使用 简单的 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 转储以确保数组具有有效项。

编辑:

Apache 日志:

[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.

【问题讨论】:

  • 阿帕奇说什么?你能发布错误日志吗?

标签: php simple-html-dom


【解决方案1】:

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

子进程以状态 255 退出

请看这里:
PHP Out of Memory - Crashes Apache?

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

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

【讨论】:

  • 是的!我忘记了我有一个调用页面的循环,当我调用 file_get_html 时,我没有释放该内存。非常感谢!
【解决方案2】:

尝试改变

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

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

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

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

【讨论】:

  • 问题出在foreach循环中,我注释了循环内的所有内容,只留下了迭代,但仍然导致它崩溃。
猜你喜欢
  • 1970-01-01
  • 2012-08-12
  • 1970-01-01
  • 2013-05-28
  • 2012-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多