Bug #80117 [Com]: Apache and PHP leaking memory and also does not releasing it

From: Date: Thu, 17 Sep 2020 17:29:31 +0000
Subject: Bug #80117 [Com]: Apache and PHP leaking memory and also does not releasing it
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229058@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80117&edit=1 ID: 80117 Comment by: danack@php.net Reported by: gilperon at gmail dot com Summary: Apache and PHP leaking memory and also does not releasing it Status: Not a bug Type: Bug Package: *General Issues Operating System: WINDOWS 10 AND CENTOS 8 PHP Version: Irrelevant Block user comment: N Private report: N New Comment: > danack@php.net did you read everyhing I told you? Yes. > and error_log file will say that apache is "Out of > memory". I'm being blind. I can't see anything about a log file. Where is this in your bug report? Okay, this is a wild guess; are you having a problem with a script using all the memory, and are trying to make a reproduce case? Previous Comments: ------------------------------------------------------------------------ [2020-09-17 17:23:03] gilperon at gmail dot com danack@php.net did you read everyhing I told you? As you execute that same script a few dozen times, it will end up consuming all system RAM memory and error_log file will say that apache is "Out of memory". You said "Until you actually see some result that causes an actual problem". So, isnt this a problem? Apache is yelling at me, saying I have no more memory after my server receives only a few requests (not at the same time, the requests are mostly one after another). If you think this is not a problem, I have no idea what you consider being a problem. ------------------------------------------------------------------------ [2020-09-17 17:12:38] danack@php.net Hi, It turns out that computers are complicated. Exactly what is happening on your system isn't obvious, but trying to figure out of something has a memory leak or not, just by looking at Windows Task Manager isn't the way to go about it. It could just be that "that's how Apache delays releasing memory", or "that's just how windows task manager is". If there was a real memory leak, you'd be able to make apache crash (or at the very least slow down drastically). But seeing high memory usage numbers in Task Manager doesn't actually indicate a fault. Until you actually see some result that causes an actual problem (like a reproducible crash, or unable to serve requests), please refrain from opening bug tickets about system metrics you are seeing, as they aren't a useful thing for people to be looking at. ------------------------------------------------------------------------ [2020-09-17 16:49:47] gilperon at gmail dot com Description: ------------ This case is similar to a previous one I reported in this bug tracker, but that other case was solved by simply using "gc_mem_caches". HOWEVER this new case DOES NOT work by using "gc_mem_caches". I am running latest APACHE (2.5.x) + PHP (7.x) on my Win10 computer which has 8GB of RAM. All configurations are default. When I start my Apache and check Windows Task Manager it shows the two Apache processes are using about 5 to 6 MB of RAM. Great. Now I saved the code below on a test.php file and execute it using my browser like this http://localhost/test.php The contents of that file is pretty simple, just this: <?php set_time_limit(0); ini_set("memory_limit","-1"); for ($i=0;$i<20000000;$i++) { $a[] = md5($i); } unset($a); gc_mem_caches(); ?> After executing the code above, one of Apache process RAM went up to close to 1GB and after a few seconds it went down to the original 5-6MB (same as when I started Apache). However if I execute that exactly same code again (without restarting/reloading Apache), after the end I will be left with Apache using 400MB. And that's not all! If I keep executing that same code again, and again, and again... Apache RAM usage increases every single time the script finishes its execution by about 180MB. So Apache is probably leaking memory somewhere and is never releasing it. I already tried "gc_enable(); gc_collect_cycles();" but it does not work (of course, I am not using references). Test script: --------------- <?php set_time_limit(0); ini_set("memory_limit","-1"); for ($i=0;$i<20000000;$i++) { $a[] = md5($i); } unset($a); gc_mem_caches(); ?> Expected result: ---------------- Memory should go back to 5-6MB. Actual result: -------------- Memory leak or increase memory usage. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80117&edit=1

« previous php.bugs (#229058) next »