简体   繁体   English

PHP应用程序耗尽内存

[英]PHP application running out of Memory

I am writing a set of classes for a crawler, it crawls a start page, pulls three links based on parameters (found using Simple Html Dom Parser allowing use of jquery like selectors), crawls those pages, then goes to page 2, picks the next 3 pages. 我正在为一个爬虫编写一组类,它抓取一个起始页,根据参数拉出三个链接(使用Simple Html Dom Parser找到允许使用类似选择器的jquery),抓取这些页面,然后转到第2页,选择接下来的3页。 Current max pages is 57 times. 当前最大页面是57次。

Needless to say I am getting: 不用说我得到了:

Allowed memory size of 50331648 bytes exhausted error message. 允许的内存大小为50331648字节耗尽错误消息。

Is there any way I can avoid running out of memmory. 有什么办法可以避免忘记记忆。

To let you know, after pulling in the contents of the first page, I run a go() function, which continuosly pulls in the pages until $this->maxpages is reached. 为了让你知道,在拉入第一页的内容后,我运行了一个go()函数,它连续拉入页面,直到达到$ this-> maxpages。 I suppose I could run the loop when instantiating the classes, but would this help. 我想我可以在实例化类时运行循环,但这会有所帮助。

You can adjust the memory limit: 您可以调整内存限制:

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

But I'd try to make the script use less memory. 但我试着让脚本使用更少的内存。 Make sure you are freeing data / references to anything that no longer needs to exist. 确保将数据/引用释放到不再需要存在的任何内容中。

memory_get_usage() can be useful in debugging where the memory usage is accumulating. memory_get_usage()可用于调试内存使用量累积的位置。

Also, if you aren't using PHP 5.3, you may consider upgrading since its garbage collector is better. 此外,如果您不使用PHP 5.3,您可以考虑升级,因为它的垃圾收集器更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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