Jump to content
TrueMember

Fatal error: Allowed memory size of bytes exhausted

Recommended Posts

Hi again,

I did a simple request and i get right response from curl_exec($ch); but when i call the static method str_get_html my result is always the same.

Quote

Fatal error:  Allowed memory size of 536870912 bytes exhausted

I tried increase the memory memory_limit=2048M but the result is the same. Proof of memory limit: Memory Limit

I also tried ->clear(); unset();  but doesn't work. 

I'm using the following library:

kub-at/php-simple-html-dom-parser

My code:

$url = "https://www.php.net";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, []);
$this->callback = HtmlDomParser::str_get_html(curl_exec($ch));
....

Any tips? I can use regular expression, but will be my last choice.

Thank you!

Share this post


Link to post
Share on other sites

If you tried increasing the memory limit and the memory limit didn't increase then you didn't increase the memory limit.

You did you edit the correct file? Restart PHP or your web server?

Share this post


Link to post
Share on other sites

A common cause of memory exhaustion is infinite recursion. Are you sure about that callback?

Share this post


Link to post
Share on other sites
9 hours ago, requinix said:

If you tried increasing the memory limit and the memory limit didn't increase then you didn't increase the memory limit.

You did you edit the correct file? Restart PHP or your web server?

Yes, you can see the proof in the first post.

59 minutes ago, Barand said:

A common cause of memory exhaustion is infinite recursion. Are you sure about that callback?

  I don't understand why. To try i added the code to controller and it happens again.. :(

$url = "https://www.php.net";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, []);
$response = curl_exec($ch);
$dom = HtmlDomParser::str_get_html($response);
echo '<pre>';
        print_r($dom->find(".title"));
        echo '</pre>';
$dom->clear();
unset($dom);
die();

 

Share this post


Link to post
Share on other sites

The problem is that you are trying to print_r the result.  The object created by that library is large and recursive so you can't just easily dump it.

 

  • Great Answer 1

Share this post


Link to post
Share on other sites
37 minutes ago, kicken said:

The problem is that you are trying to print_r the result.  The object created by that library is large and recursive so you can't just easily dump it.

 

Thank you, that's it!😀

Share this post


Link to post
Share on other sites

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.