Fatal error: Out of memory [closed]

ε祈祈猫儿з 提交于 2019-12-25 18:00:34

问题


error:

Fatal error: Out of memory (allocated 123469824) (tried to allocate 71 bytes) in /home/test/tset/tset.net/public_html/test/simple_html_dom.php on line 1236

Yes, I know that many of these issues were. But I did not realize how easy it is to avoid this mistake. I need if this error occurs, simply start the loop from the next value.

I use simplehtmldom

code:

$html = file_get_html('http://www.windowsaffinity.com/?p=14721');

EDIT: YES *maximum memory size is insufficient*


回答1:


You can't catch fatal errors in PHP. They are, after all, fatal.

Without knowing exactly what you're trying to do, would it be possible to store some kind of counter or other position parameter in a database or other file to "hold your place" until you can restart the script.

If you're running out of memory, you have bigger issues. Either your hosting is much too tiny for what you're trying to do, or you're biting off more than you can chew (or both). Try breaking your process into multiple pieces, and call unset() and/or assign null to variables when you're done with them to limit the space you're using, and to tell the garbage collector that your objects are eligible to be collected.




回答2:


You can raise php's memory limit, via ini_set, but this should only be done on a per-script bases (eg, importing data from a very large xml/etc file). Excellent question that addresses raising memory limit - Increasing PHP memory_limit. At what point does it become insane? .

Edit: Read update post, in your case I'd raise the memory limit - assuming your writing a quick script for one time use. If ini_set is disabled (ie, most likely if your on a shared host), set memory_limit in php.ini.

Another option would be to use sockets to fetch the page (read data in small chunks, and save to file or w/e) or run a system command (eg, wget -O /save/here.txt http://blah.com)



来源:https://stackoverflow.com/questions/7087183/fatal-error-out-of-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!