Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Simple HTML Dom Memory Issue

Tags:

dom

php

parsing

I'm running into memory issues with PHP Simple HTML DOM Parser. I'm parsing a fair sized doc and need to run down the DOM tree...

1)I'm starting with the whole file:

$html = file_get_html($file);

2)then parsing out my table:

$table = $html->find('table.big'); 

3)then parsing out my rows:

$rows = $table[0]->find('tr');

What I'm ending up with are three GIANT objects... anyone know how to dump an object after I've parsed it for the data I need? Like $html is useless by step 3, yet, it's the largest of all the objects.

Any ideas?

Is there a way to drill down to my table rows out of the original $html object?

Thanks in advance.

EDIT:

I've managed to skip step two with:

$rows = $this->html->find('table.big tr');

But am still running into memory issues...

like image 807
Howard Zoopaloopa Avatar asked Jul 21 '10 22:07

Howard Zoopaloopa


2 Answers

I may be little late...to answer as i joined late...so the answers given above are not correct. unset only unsets the $html not its properties. So to clean up memory and kick off the memory issue is :

use $html->clear();.

I think u didint read the class code before using it. clear() function destroy/release the memory eaten up by the $html object.This function is internal function of simple_html_dom.This function immediately take effect. So u dont have to wait whole day or program termination to take effect.

like image 152
Aakash Sahai Avatar answered Oct 24 '22 00:10

Aakash Sahai


You can increase the memory limit.

ini_set('memory_limit', '64M');

or clear the memory with this code

$html->__destruct();
unset($html);
$html = null;
like image 41
Nanhe Kumar Avatar answered Oct 24 '22 01:10

Nanhe Kumar