It is not possible to have memory leaks from PHP scripts between different requests (when using the Apache default configuration), because the variables and code used in the same request are freed at the end of this request, and the PHP memory allocator is restarted for the next request. However, errors in the interpreter or PHP extensions may leak memory separately.
A much bigger problem is that Apache child processes have PHP memory space inside them. They swell to allocate peak memory usage of the PHP script, and then keep this memory allocation until the child process is killed (as soon as the process asks the kernel to allocate part of the memory, this memory will not be released until the process dies). For a more detailed explanation of why this is a problem and how to deal with it, see My answer to Server Error .
A memory leak in a script where variables are not disconnected and the PHP garbage collector fails is very rare - most PHP scripts run for several hundred milliseconds, and this is usually not enough for even a serious memory leak to occur.
You can control how much memory your PHP script uses with memory_get_usage() and memory_get_peak_usage() - there is also a good explanation of memory usage and protection methods in the PHP manual .
PHP memory management is described in detail in this article .
edit: You can define compiled modules in Apache using httpd -l - the default values ββdepend on the OS configuration and repository configuration. There are many ways PHP can interact with Apache - the most detailed here .
source share