简体   繁体   中英

Scraping much data from different URLs with simple_html_dom.php

i basically want to do exactly something like this: Simple Html DOM Caching

i got everything to work so far, but now i'm getting the following error because i scrape many sites (6 at the moment, i want up to 25 sites):

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 39 bytes)

i'm a php newbie =/...so, how can i "serialize" the scraping process step by step that my memory don't give up? :-)

code sample:

// Include the library
include('simple_html_dom.php');

// retrieve and find contents
$html0 = file_get_html('http://www.site.com/');
foreach($html0->find('#id') as $aktuelle_spiele);

file_put_contents("cache/cache0.html",$aktuelle_spiele);

thank you very much in advance for your help!

In your php.ini, change this line:

memory_limit = 32M

With this one:

memory_limit = 256M //or another greater value

Or add this piece of code at the start of every php script that use simple_html_dom:

ini_set('memory_limit', '128M'); //or a greater value

you can run a memory increase at the start of your script.

Like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM