Memory problem in PHP simple HTML DOM
I was using PHP Simple HTML dom, a great and free library for parsing html pages and retreiving info from it. I really liked it.. But when it comes to parsing many differents pages of some website in one php script, you will get an error:
Allowed memory size of 67108864 bytes exhausted,
and this is because simple HTML dom don't free up the memory in real time, so the solution is:
Each time you create a dom object ( foe exemple using: $html = file_get_html("http://someurl/"); or str_get_html... ), then when you don't need it anymore you have to call _destruct:
$html->_destruct();
unset($html);
Allowed memory size of 67108864 bytes exhausted,
and this is because simple HTML dom don't free up the memory in real time, so the solution is:
Each time you create a dom object ( foe exemple using: $html = file_get_html("http://someurl/"); or str_get_html... ), then when you don't need it anymore you have to call _destruct:
$html->_destruct();
unset($html);
7 comments:
-
Anonymous said...
-
thanks so much for posting this!
but there is a type. it should be __destruct, not _destruct. -
March 15, 2011 at 12:46 AM
-
Wojtek said...
-
Thanks a lot!
I was looking for a solution to this problem and that was it.
Would be good to fix the typo, though. Like the guy above wrote, there's a double _
Cheers. -
April 13, 2011 at 4:28 AM
- Facebook App Developer said...
-
yes,
i also was surfing the net for this problem like Wojtek,
and now i have solve my prob,
thanks -
April 23, 2012 at 1:59 AM
-
Anonymous said...
-
Thank you very much!
-
August 7, 2012 at 9:07 AM
- TechToyz said...
-
Again an awesome Article
-
August 22, 2012 at 5:29 AM
- rize wordpress said...
-
Our company has cumulative decades of experience programming PHP in all sorts of applications. PHP Programmers
-
September 6, 2012 at 2:35 AM
- Lia said...
-
Thanks for sharing this information and I know it can helpful. I will save it so that if I can encounter a problem in PHP I can use it. Keep it up.
-
December 17, 2012 at 10:54 PM
Subscribe to:
Post Comments (Atom)
Categories
- 1-General (3)
- 2-Getting started (4)
- 3-Strings (10)
- 4-Server config (1)
- 5-Best scripts (7)
- email (4)
- files (6)
- Forms (3)
- If statements (3)
- Loop statements (2)
- Mysql (2)
- Server variables (3)
- Sessions (1)
- Tutorials-planet.com (1)
- web hosting (1)
- You need a programmer ? (1)





