问题
$html = file_get_html('http://www.oddsshark.com/mlb/odds');
echo $html;
When ehcoed, the error message in the title of this question appears? I've had problems that are similar to this before. In all cases, I didn't actually need to increase the memoery in php.ini. Rather, there was a missing curly bracket that was needed to close a loop. This page that I'm requesting via the file_get_html function appears fine in my browser, but it just won't let me echo the html via php.
Any ideas?
回答1:
Why not use a library that is more memory optimized, simple HTML DOM is just not necessary any longer:
$html = new DOMDocument;
$html->loadHTMLFile('http://www.oddsshark.com/mlb/odds');
echo $html->saveHTML();
More suggestions are available with the reference question about that topic:
- How do you parse and process HTML/XML in PHP?
回答2:
increase your memory limit in php.ini file
search for
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 128M
in your php.ini file and increase it to 512M
回答3:
I really don't think this usage justify increasing the memory. If it go over, it's because there is a problem : Simple HTML DOM Parser is known to suffer from memory leak.
If you just need to retrieve the content of a remote page using HTTP, just do the following. This is the simplest and most resource efficient way I know to retrieve content from a remote page:
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
If you need to do more advance queries, you may look into cURL: http://php.net/manual/en/book.curl.php
回答4:
Edit your php.ini file
memory_limit=512M
OR add a line in your PHP file:
ini_set('memory_limit', '512M');
And the error will get resolved.
Note: You can put your value instead of 512M
.
来源:https://stackoverflow.com/questions/16627637/fatal-error-allowed-memory-size-of-33554432-bytes-exhausted