Click to See Complete Forum and Search --> : PHP & system resources


Arisen
01-11-2006, 12:37 PM
I recently set up PHP for Apache and set up oen site in PHP. Now the site is only accessed by em for for development of the site, so traffic is very lmited. But I have noticed that my RAM resources as soon as the site is accessed jump and stay at this raised level until Apache or the computer is restarted. I have also noticed that PHP creates and temp file (.~php) for every php file that is accessed and they are not deleted after use (but also don't stack up). Any ideas what is going on here and how I cn get PHP to go away when it's not in use?

Thanks

ph34r
01-11-2006, 02:56 PM
Linux keeps things in RAM even after it is done processing them, just in case it needs it again. Should it need more RAM for a running process, the extra used by things that are "old" is freed.

bwkaz
01-11-2006, 07:46 PM
And you can check whether this is what's happening by comparing a few of the lines of the output of free. For instance:

$ free
total used free shared buffers cached
Mem: 776332 754832 21500 0 16268 573364
-/+ buffers/cache: 165200 611132
Swap: 393552 184 393368
$ You'll see here that the total RAM is 776332, and 754832 of that is marked "used". But this "used" value counts both processes that are using RAM and kernel cache (etc.) that's only there to speed up disk accesses. The "+/- buffers/cache" line shows the total RAM used by processes only (165200, in my case); this does not include the kernel caches, etc., because those are usually freed up first if a new process needs RAM.

If you see an increase in the "+/- buffers/cache" row's "used" column, then your PHP process (or some process on the system) is actually using the extra memory. But if the only increase is in the "Mem:" row, then don't worry about it; that RAM is only being used to speed up subsequent file accesses, and it'll be freed by the kernel as it's needed.