We are running PHP as an Apache module. Issue is that we have a website on our server whose memory limit is set to 32M via .htaccess
php_value memory_limit 32M
But when running a particular URL of that site, the HTTP memory usage goes upto 2.3 GB. I checked their code and did not find any place the memory_limit is being modified realtime.
If you want to be sure, set the memory with php_admin_value in the httpd conf for the site. A value set with php_admin_value can’t be overridden later on.
Any way - The memory limit only governs how much memory a single php process will allow. If you have multiple requests, they add up. Also, Apache might use memory other than that - the php process doesn’t know about that. Finally, it only controls memory usage of php variables - not external extensions. For example, if the program uses an xml parser to parse a big document, it won’t count. (I’m actually not 100% sure about this last part, so go look it up before you take my word for it, but I’m fairly sure that it’s true). Hope that helps a bit.
Have implemented php_admin_value suggestion. Lets see how it impacts.
Since we are running Apache with mpm_prefork, each request is served by a separate process. I did some self testing of loading big files like images etc. using imagecreatefromfile(), but it does add up to PHP memory (checked via memory_get_peak_usage). In anycase 8M memory limit led to 27M Apache process, but 32M limit leading to 2.3 GB is difficult to digest.
It can be some memory leak bug etc. Cannot pin-point.
Does the script/URL halt with an out of memory error? You seem to be suggesting that it isn’t? How do you know it’s using 2.3GB when limit is set at 32M? The script should halt when the script itself exceeds 32MB. And as kyberfabrikken suggests, this will exclude programs such as Imagemagick etc.
If you are manipulating hi-res images (uncompressed when in memory) then you could very quickly reach this limit, however, 2.3 GB would seem a bit high!?
I am certainly sure about 2.3 GB thing. Checked it via ‘top’ and ‘links http://localhost/whm-server-status’ commands. Moreover imagecreatefromjpeg is a GD extension function. Could not find much on Google on memory_limit and PHP extensions.
But I feel memory_limit applies to everything after doing my own little testing. On server we are using 5.2.16 version. Could be memory leak, bug etc. Don’t know.