Re: PHP 4.0 Bug #5641: php module fails to release memory
| From: | Michel Jansens | Date: | Tue, 18 Jul 2000 08:37:02 +0000 |
| Subject: | Re: PHP 4.0 Bug #5641: php module fails to release memory | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-24854@lists.php.net to get a copy of this message | ||
Hi ,
Well the string created by this script is 20,971,520 ( 10*2^21) long so It should at least take 20MB of memory...
My experience is that PHP takes memory about 2 times the size of a string so that's already 40MB, probably for easy management and faster handling (is it linked list implemented?).
Anyway, the script was just an example, I'm (re)writing a Webmail application and detaching attachment can sometime take up a lot of memory, but most of the time the need for memory is quite low.This means that after a few days you end up with all your httpd process taking up a lot of (unused) RAM and swap space.
Stanislav, when the PHP module of the http process finishes a script, all memory is freed (?). then all memory that was allocated is released, so all the "top memory" should be freed and be reclaimed by the system.
If blocks allocated by PHP are too small, why not make them bigger? ;-) i.e allocate big chunks and breaking them up as needed by the interpreter? when the script finishes PHP could free those big chunks which would be given back to the system.
These are just candid remarks, I'm not very fluent in UNIX memory management nor PHP internals, and I find PHP is great anyway.
My best solution is probably to run PHP as a CGI for the tasks that use up a lot of memory. This way all the memory is released each time at the end.
Thank you both for your answersMichel Jansens RL>>Are you sure it has anything to do with that script? That shouldn't take RL>>up very much memory at all, and on my system I don't see any noticeable RL>>increase in memory usage. RL>> Since PHP never terminates, your httpd processes will grow to RL>> the size of your most memory hungry script and stay there. SM>>That's is not exactly true. free() frees memory iff there's no memory SM>>blocks "above" this block and there's enough memory to free. Definition of SM>>"enough" depends on implementation. Also, large (more than 64K for glibc, SM>>IIRC) blocks are allocated with memmap(/dev/zero), so they are released SM>>immediately on free(). SM>>Unfortunately, PHP allocates memory often in small "chunks" and often, SM>>meaning there's not really many chances that memory will be returned to SM>>OS. But that's not too much problem since PHP will reuse this memory and SM>>PHP memory manager is build to never really "leak" memory.
Before running the script below all httpd processes take 1169KB RAM and 9352 SWAP After one of the http process takes 6292KB RAM and 50,336KB SWAP Is this normal behaviour? is there a way to prevent this? <?php$a="0123456789"; for($i=0;$i<21;$i++)$a.=$a; print strlen($a); unset($a);?> -- Michel Jansens --------------------------------------------------------------------------- Service Reseau, Universite Libre de Bruxelles (ULB) email: mjansens@ulb.ac.be surface mail: Michel Jansens CP 197 Universite Libre de Bruxelles 50 Av. F.Roosevelt 1050 Bruxelles Belgium