PHP内存垃圾回收 [英] PHP memory garbage collection
问题描述
嗨!
我有一个使用大量内存的脚本和一个具有内存限制的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-limit
set to 10 Mb. The script of course doesn''t finish running. :(
The program is rather simple - it parses XML into an array and then starts
the loop that inserts data into the database. If I use a very large XML
file then the PHP crashes inside the loop (Fatal error: Allowed memory size
of 10485760 bytes exhausted) - indicating that the problem lies within loop
somewhere.
Can I trace memory consumption of a PHP script so I can determine where the
memory is wasted?
If PHP uses all the memory (and frees nothing) until the end of the script
then that could be the problem - is there any way I can force it to do
garbage collection?
Any comment on how PHP uses memory would be appreciated - I would really
hate to have to break the script into smaller pieces (or change ISP for
that matter :) ).
Thanks!
Anze
推荐答案
任何人?请?我真的需要解决这个问题...
有没有办法测量当前的内存消耗?
问候,
< br $> b $ b anze
Anze写道:
Anybody? Please? I really need to solve this...
Is there a way to measure current memory consumption?
Regards,
Anze
Anze wrote:
嗨!
我有一个脚本,它使用了很多内存和ISP的内存限制设置为10 Mb。剧本当然没有完成。 :(
程序相当简单 - 它将XML解析为数组,然后启动将数据插入数据库的循环。如果我使用非常大的XML
文件然后PHP在循环内崩溃(致命错误:允许的内存大小为10485760字节耗尽) - 表明问题在于某个地方的循环内部。
我可以跟踪内存消耗一个PHP脚本,所以我可以确定内存浪费的位置?
如果PHP使用所有内存(并且没有任何内容)直到脚本结束
那么那可能是问题 - 有什么方法可以强迫它做垃圾收集吗?
关于PHP如何使用内存的任何评论都会受到赞赏 - 我真的很想
讨厌将脚本分解成更小的部分(或更改ISP以获得重要的事情:))。
谢谢!
Anze
Hi!
I have a script that uses a lot of memory and an ISP that has memory-limit
set to 10 Mb. The script of course doesn''t finish running. :(
The program is rather simple - it parses XML into an array and then starts
the loop that inserts data into the database. If I use a very large XML
file then the PHP crashes inside the loop (Fatal error: Allowed memory
size of 10485760 bytes exhausted) - indicating that the problem lies
within loop somewhere.
Can I trace memory consumption of a PHP script so I can determine where
the memory is wasted?
If PHP uses all the memory (and frees nothing) until the end of the script
then that could be the problem - is there any way I can force it to do
garbage collection?
Any comment on how PHP uses memory would be appreciated - I would really
hate to have to break the script into smaller pieces (or change ISP for
that matter :) ).
Thanks!
Anze
Anze写道:
任何人?请?我真的需要解决这个问题...
有没有办法测量当前的内存消耗?
问候,
Anze
Anze写道:
Anybody? Please? I really need to solve this...
Is there a way to measure current memory consumption?
Regards,
Anze
Anze wrote:
嗨!
我有一个使用大量内存的脚本和一个内存限制的ISP >设定为10 Mb。剧本当然没有完成。 :(
程序相当简单 - 它将XML解析为数组,然后启动将数据插入数据库的循环。如果我使用非常大的XML
文件然后PHP在循环内崩溃(致命错误:允许的内存大小为10485760字节耗尽) - 表明问题在于某个地方的循环内部。
我可以跟踪内存消耗一个PHP脚本,所以我可以确定内存浪费的位置?
如果PHP使用所有内存(并且没有任何内容)直到脚本结束
那么那可能是问题 - 有什么方法可以强迫它做垃圾收集吗?
关于PHP如何使用内存的任何评论都会受到赞赏 - 我真的很想
讨厌将脚本分解成更小的部分(或更改ISP以获得重要的事情:))。
谢谢!
Anze
Hi!
I have a script that uses a lot of memory and an ISP that has memory-limit
set to 10 Mb. The script of course doesn''t finish running. :(
The program is rather simple - it parses XML into an array and then starts
the loop that inserts data into the database. If I use a very large XML
file then the PHP crashes inside the loop (Fatal error: Allowed memory
size of 10485760 bytes exhausted) - indicating that the problem lies
within loop somewhere.
Can I trace memory consumption of a PHP script so I can determine where
the memory is wasted?
If PHP uses all the memory (and frees nothing) until the end of the script
then that could be the problem - is there any way I can force it to do
garbage collection?
Any comment on how PHP uses memory would be appreciated - I would really
hate to have to break the script into smaller pieces (or change ISP for
that 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 you
don''t need anymore and then unset them (unset(
var))。
>
如果您无法通过这种方式解决问题,可以通过SSH或其他方式与您的ISP联系以运行
脚本。
我不认为你会经常运行脚本或者你呢?如果你这样做,我建议你考虑一下你的b
编程的逻辑和效率。
var)).
If you can''t solve it this way, you can contact your ISP to run the
script for you through SSH or something.
I don''t think you would run the script often or do you? If you do, I
suggest thinking about the logic and effeciency about your piece of
programming.
这篇关于PHP内存垃圾回收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!