Php daemon memory leak possible

I wrote a daemon in php and want to make sure that it is not a memory leak, as it will work 24/7.

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

Q: Should I worry? I stripped the demon to simple 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); } 

FINAL REMARK + CONCLUSION: I ended up writing my own daemon shell without using the system_daemon pear. no matter how I set up this library, I could not stop it from leaking memory. hope this helps someone else.

FINAL NOTICE + CONCLUSION 2: my script has been running for more than a week and so far 1 byte of memory has not been leaked. so writing a daemon in php actually seems to be all right if you are very careful about its memory consumption.

+3
php memory-leaks daemon
Nov 06 2018-10-06
source share
4 answers

I have the same problem. Perhaps the best idea is to report a new bug in PEAR

By the way, code like this doesn't show 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); } 

See how the problem is System_Daemon :: info ().

+5
Nov 08 '10 at 15:50
source share

Turns out file_get_contents is a memory leak. Whenever I disconnected this line, peak memory usage was stable. When I comment on this, peak memory usage will increase by 32 bytes at each iteration.

Replaced the call to file_get_contents (used to extract the number inside the pid file in / var / run) with fread , and solved this problem.

This patch will be part of the next version of System_Daemon .

Thank you, who (cannot find the corresponding nickname) also reported this error ( # 18036 ) d was probably never known.

Thanks again!

+4
Nov 09 '10 at 11:09
source share

You can try using the new garbage collector in PHP 5.3 to prevent circular link problems.

+2
Nov 06 '10 at
source share

You should not use PHP to write a daemon . What for? Because PHP is not a language mature enough to work for hours, days, weeks, or months. PHP is written in C, all the magic it provides must be handled. Garbage collection, depending on your version, may or may not work, depending on which extensions you compiled and used. Yes, if they come with official releases, they should β€œplay well,” but do you check which edition you use? Are you sure that all downloaded extensions understand that they can work for more than 10 - 30 seconds? Given that most deadlines never detect leaks, are you sure they even work?

I'm pretty close to " not using a regular expression to parse an HTML ad regarding this, as I see the question more and more, Twice today that I know of.

Would you use scrap as a toothpick? Neither Zend, nor Roadsend, nor PHC are mature enough to handle work for any period of time that could be considered protracted, given the expected lifetime of PHP when rendering a web page. Yes, even with the GC capabilities provided by the C ++ PHP compiler, it is unwise to write a daemon in PHP.

I hate the answers that you can't do that, with that , but in this case it’s true, at least for now.

0
Nov 07 '10 at 18:14
source share



All Articles