0

I'm using Simple HTML Dom. I'm trying to run the following: (with 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);
}

If I comment out the foreach loop, it runs fine. Otherwise, the apache crashes.

One important note: If I comment out the inside of the foreach loop, it still crashes. I added the var dump to make sure that the array has valid items.

EDIT:

Apache logs:

[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.
Novak
  • 2,760
  • 9
  • 42
  • 63

2 Answers2

2

this might be a memory leak:
since your apache says:

child process exited with status 255

see here:
PHP Out of Memory - Crashes Apache?

Due to php5 circular references memory leak, after creating DOM object, you must call $dom->clear() to free memory if call file_get_dom() more then once.

from here: http://simplehtmldom.sourceforge.net/manual_faq.htm#memory_leak

Community
  • 1
  • 1
ivoba
  • 5,780
  • 5
  • 48
  • 55
  • Yep! I forgot I had a loop calling the pages, and when I called file_get_html I didn't free that memory. Thank you so much! – Novak Jul 10 '12 at 14:17
1

Try to change

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

to

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

or

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

$obj->method is an instance call. Class::method is an static call. $this::method does probably something weird...

Ron
  • 1,336
  • 12
  • 20
  • The problem is in the foreach loop, I commented everything inside the loop, leaving only the iteration, but it still causes it to crash. – Novak Jul 10 '12 at 13:56