Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

How does the PHP maximum memory limit affect the memory that an Apache process consumes? If for example I've set it to 256MB, does this mean that every process will try to allocate this amount of memory, or all the processes together or what?

share|improve this question

2 Answers 2

PHP's memory limit is the maximum amount of memory that will be allocated within PHP. In the default MPM, that means each Apache child will use, at most, (Apache overhead+memory_limit) bytes of RAM. Of course, that discounts the possibility of other extensions also allocating memory, but that's a separate issue. Lastly, it should be noted that the children don't pre-allocate memory_limit bytes of RAM at startup; it's simply a hard cap that's enforced as needed.

share|improve this answer
    
+1, that's how I understood it as well. –  Kyle Smith Jun 26 '10 at 21:25

But, for approx 100ms, it does use memory_limit. My webhost installed CloudLinux, with a reasonable 256MB RAM limit. My AJAX code, calling 4 php pages simultaneously, suddenly stopped working, with 500 errors. (Suspected a lot of things, erroneously) On this server, memory_limit was 128MB, host kindly reduced it to 64MB. Loading 5 php pages (actually basic html, saved with .php extensions) as my Homepages, I was able to eliminate any Javascript or PHP code. CloudLinux gave 500 errors - yet here is the "php" it was loading 5 of:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>First Page</title>
</head>
<body>
<h1>First Page</h1>
</body>
</html>

So, specifically, it does use memory_limit of RAM - only for a very short time, presumably to test the allocation possibility. This becomes a problem with CloudLinux (excellent idea), high PHP memory_limit and code calling multiple PHP pages.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.