2

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?

2 Answers 2

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.

1
  • +1, that's how I understood it as well.
    – Kyle Smith
    Jun 26, 2010 at 21:25
1

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.

You must log in to answer this question.