PHP守护进程可能的内存泄漏 [英] php daemon possible memory leak

查看:331
本文介绍了PHP守护进程可能的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用php编写了一个守护进程,并希望确保它不会泄漏内存,因为它将以24/7运行.

i've written a daemon in php and want to make sure it doesn't leak memory, as it'll be running 24/7.

即使以最简单的形式为守护程序使用memory_get_peak_usage也会报告该脚本在每个周期消耗更多的内存.另一方面,memory_get_usage不会增长.

even in its simplest form memory_get_peak_usage for a daemon will report that the script consumes more memory for each cycle. memory_get_usage on the other hand will not grow.

问题是:我应该担心吗?我已经将守护程序简化为基本知识,但这仍在发生.有什么想法吗?

the question is: should i worry? i've stripped down the daemon to the bare basics but this is still happening. any thoughts?

#!/usr/bin/php -q

<?php
require_once "System/Daemon.php";
System_Daemon::setOption("appName", "smsd");
System_Daemon::start();
while(!System_Daemon::isDying()){
 System_Daemon::info("debug: memory_get_peak_usage: ".memory_get_peak_usage());
 System_Daemon::info("debug: memory_get_usage: ".memory_get_usage());
 System_Daemon::iterate(2);
}

最后的提示+结论:我最终写了自己的守护程序包装程序,而不是使用pear的system_daemon.不管我如何调整此库,我都无法阻止它从内存泄漏.希望这对其他人有帮助.

FINAL NOTE + CONCLUSION: i ended up writing my own daemon wrapper, not using pear's system_daemon. regardless of how i tweaked this library i could not stop it from leaking memory. hope this helps someone else.

最后的提示+结论2:我的脚本已经投入生产超过一周,仍然没有泄漏1个字节的内存.因此-只要您非常注意它的内存消耗,就可以用php编写一个守护程序似乎是可以的.

FINAL NOTE + CONCLUSION 2: my script has been in production for over a week and is still not leaking 1 bytes of memory. so - writing a daemon in php actually seems to be ok, as long as you're very careful about its memory consumtion.

推荐答案

我遇到了同样的问题.也许最好的办法是在 PEAR 报告新的错误

I got the same problem. Maybe the best idea is to report new bug at PEAR

顺便说一句,类似的代码并没有显示该记忆泄漏:

BTW, code like that doesn't show that memleak:

#!/usr/bin/php -q

<?php
require_once "System/Daemon.php";
System_Daemon::setOption("appName", "smsd");
System_Daemon::start();
while(!System_Daemon::isDying()) {
 print ("debug: memory_get_peak_usage: ".memory_get_peak_usage()."\n");
 print ("debug: memory_get_usage: ".memory_get_usage()."\n\n");
 System_Daemon::iterate(2);

}

看起来像System_Daemon :: info()是个问题.

Look's like System_Daemon::info() is a problem.

这篇关于PHP守护进程可能的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆