本文介绍了PHP内存垃圾回收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嗨! 我有一个使用大量内存的脚本和一个具有内存限制的ISP 设置为10 Mb。剧本当然没有完成。 :( 程序相当简单 - 它将XML解析为一个数组,然后启动 将数据插入数据库的循环。如果我使用的话非常大的XML 文件然后PHP在循环内崩溃(致命错误:允许的内存大小 的10485760字节耗尽) - 表明问题出在循环中 某处。 我可以追踪PHP脚本的内存消耗,这样我就可以确定内存浪费在哪里吗? 如果PHP使用所有内存(并且没有任何内容)直到脚本结束 那么这可能是问题 - 我有什么方法可以强迫它做 垃圾回收? 任何关于PHP如何使用内存的评论都会受到赞赏 - 我真的会感到好意,因为讨厌不得不打破将脚本分成小块(或更换ISP为 ,重要的是:))。 谢谢! 安泽Hi!I have a script that uses a lot of memory and an ISP that has memory-limitset to 10 Mb. The script of course doesn''t finish running. :(The program is rather simple - it parses XML into an array and then startsthe loop that inserts data into the database. If I use a very large XMLfile then the PHP crashes inside the loop (Fatal error: Allowed memory sizeof 10485760 bytes exhausted) - indicating that the problem lies within loopsomewhere.Can I trace memory consumption of a PHP script so I can determine where thememory is wasted?If PHP uses all the memory (and frees nothing) until the end of the scriptthen that could be the problem - is there any way I can force it to dogarbage collection?Any comment on how PHP uses memory would be appreciated - I would reallyhate to have to break the script into smaller pieces (or change ISP forthat matter :) ).Thanks!Anze推荐答案 我已经在想一个解决方案,我的错...... 查看你的脚本你有全局变量的地方你不再需要b $ b不再需要它们(未设置(I''m already thinking of a solution, my fault...Look into your script for where you have global variables which youdon''t need anymore and then unset them (unset( 这篇关于PHP内存垃圾回收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!