Jump to content

High CPU load on simple_html_dom


etrader

Recommended Posts

I successfully load a page by simple_html_dom.php (developed in simplehtmldom.sourceforge.net) as

$html = file_get_html('externalpage');

 

But sometimes this make a high load on CPU and the page does not load for a long time (probably due to the external site server). How can I skip the process when it is not normal to avoid high CPU usage?

Link to comment
Share on other sites

download the file first?

 

(untested)

$cachepage = "cache/pagename.html";
$external = "http://google.com";
if(!file_exists($cachepage)) {
	$ch = curl_init($external);
	$fp = fopen($cachepage,'w');
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_FILE, $fp);
	curl_exec($ch);
	curl_close($ch);
	fclose($fp);
}
$html = file_get_html($cachepage);
unset($cachepage);

Link to comment
Share on other sites

download the file first?

 

(untested)

$cachepage = "cache/pagename.html";
$external = "http://google.com";
if(!file_exists($cachepage)) {
	$ch = curl_init($external);
	$fp = fopen($cachepage,'w');
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_FILE, $fp);
	curl_exec($ch);
	curl_close($ch);
	fclose($fp);
}
$html = file_get_html($cachepage);
unset($cachepage);

 

The only problem I have is that it writes pagename.html with chmod 644, and then unset cannot delete it or re-writing in the next run.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.