Strange memory problem - please help

Hi,

I have a virtual server, which I created from an adapted template and account plan, which has a resource limit of 64 MB.

However, when my client tries to run his drupal administration, he often gets error codes that there is not enough memory (limit of 32 MB exceeded).

The only thing I find in the logs is:

mod_fcgid: stderr: PHP Fatal error: Out of memory (allocated 33292288) (tried to allocate 2049 bytes) in /home/pc-explore.eu/public_html/alloc.php on line 6

So it seems there still is somewhere a limit of 32 MB. I've searched everything (I guess), but can't find a limit of 32 MB.

Can you help me out to point to the place where it could be wrong?

Status: 
Closed (fixed)

Comments

Howdy -- it sounds like you may be running into PHP's own memory limit (whereas, the limit you had set was a limit applied to every process running within that account, not just PHP).

To tweak PHP's memory limits, you can edit $HOME/etc/php.ini, look for "memory_limit", and then set it to your desired value.

It sounds like it's currently set to "32M", you may want to change it to "64M" or more.

Hi,

I don't have a $HOME/etc/php.ini, but I found /etc/php5/apache2/php.ini

I checked, the memory limit was 128, I changed it to 256.

I killed all php processes and restarted apache.

But no effect. Still the same limit of 32 MB

Hi,

I'm just thinking... Maybe this helps to find the issue:

On the server where this issue occurs, there are two drupal installations, both with other limits, one with 32MB, the other 64MB.

Could it be that the one drupal installation is in conflict with the other?

Hmm, every account created by Virtualmin should have an "etc" directory within it, and within that etc directory should be a php.ini file.

The php.ini file in the system-wide /etc directory would only be used if your PHP Execution Mode is set to mod_php, which isn't the default setting (it's also not a setting we'd recommend).

The individual etc/php.ini files are local to each domain, and those are the ones that would typically be used by default.

So it's odd that you aren't seeing one. Do you have an etc directory at all within your account's home directory, and just no php.ini file in it? Or don't you have the etc directory either?

Sorry, I misinterpreted your first reply. I do have this file, but the memory limit is just commented out.

Uncommented it, but no effect.

Also checked the php.ini in the $HOME/etc/php/php5/ directory, but same limit

The php.ini in $HOME/etc is actually just a symlink to the one in $HOME/etc/php5/php.ini.

What is the memory_limit currently set to in there, now that you've uncommented it?

That should be the limit your PHP apps are using, for your top-level Virtual Server.

Now, if you have any additional domains that are Sub-Servers -- they would have their own php.ini file within $HOME/domains/DOMAIN_NAME/etc/php.ini.

Yeah, well I checked them all. All said 128 MB. But still no effect.

Resource limits are lower, but I should expect that the server would be limited to the set limit, and not lower...

I rechecked the server - now sometimes it only goes to 22 MB (wrote a little php page to check).

I wrote a little script to check:

<?php
echo ini_get('memory_limit').'<BR />';
$arr = '';
for ($i = 1 ; $i < 100; $i++) {
        //$arr[] = str_repeat(" ", 1048576);
        $arr[] = str_repeat(" ", 1000000);
        echo 'Allocated '.$i.' Mb - memorygetusage: '.memory_get_usage().'<br />';
}
?>

and got this result:

128M Allocated 1 Mb - memorygetusage: 1322316 Allocated 2 Mb - memorygetusage: 2322448 Allocated 3 Mb - memorygetusage: 3322580 Allocated 4 Mb - memorygetusage: 4322712 Allocated 5 Mb - memorygetusage: 5322844 Allocated 6 Mb - memorygetusage: 6322976 Allocated 7 Mb - memorygetusage: 7323108 Allocated 8 Mb - memorygetusage: 8323240 Allocated 9 Mb - memorygetusage: 9323404 Allocated 10 Mb - memorygetusage: 10323536 Allocated 11 Mb - memorygetusage: 11323668 Allocated 12 Mb - memorygetusage: 12323800 Allocated 13 Mb - memorygetusage: 13323932 Allocated 14 Mb - memorygetusage: 14324064 Allocated 15 Mb - memorygetusage: 15324196 Allocated 16 Mb - memorygetusage: 16324328 Allocated 17 Mb - memorygetusage: 17324524 Allocated 18 Mb - memorygetusage: 18324656 Allocated 19 Mb - memorygetusage: 19324788 Allocated 20 Mb - memorygetusage: 20324920 Allocated 21 Mb - memorygetusage: 21325052 Allocated 22 Mb - memorygetusage: 22325184

and nothing more...

I'm unfortunately not sure why you're seeing that behavior. The memory_limit is normally governed by that php.ini file you tweaked.

If you like, I can log in and take a look.

For that, what I'd need are root login details, along with the name of the domain that you're having problems with.

If that's okay, you can either email that to eric@virtualmin.com, or you can use the Virtualmin Support module, and enable Remote Support.

Hi,

Created the support logon.

Thanks for helping me out, you folks are great!

I placed a test.php script in the public_html folder of both of the domains you mentioned to verify that PHP's memory_limit is being set correctly.

In each case, it looks like the memory_limit is indeed working properly. That's good, that rules that out as the issue.

Since you're still running into memory problems though, my suspicion is that the RAM Resource Limits aren't working as expected. What you may want to try is going into Administrative Options -> Edit Resource Limits, and increase the RAM limit to see if that resolves the issue you're seeing.

I changed the memory limits for the servers, and now everything is working fine. I guess it was a misinterpretation of the resource limits. fast cgi needs memory of it's own, next to the php_memory_limit.

I now set the resource limit to 128 MB, and the php limit to 64 MB.

Will these settings create issues on heavy loads?

Well, the higher the limits are raised, the easier it is to use more RAM.

However, I suspect most web pages on your system won't require that full amount of RAM. So if you have a few pages that require more RAM -- it's usually worth it to raise the memory limits -- since not doing so means your website won't work as you'd like it to.

One of the things I might suggest though is to edit /etc/apache2/apache2.conf, and lower the MaxClients lines in there to make sure a swarm of users (or bots) can't exhaust the memory of your system.

It looks like you have about 1.7GB of RAM available, and that you've streamlined the memory usage of your Apache processes pretty well.

I think with your configuration, that I'd suggest setting MaxClients to 30, maybe 35.

And just to make sure lingering connections don't "clog up the works", you may want to lower the "Timeout" setting in that apache2.conf from 300 to 30.

Thanks guys, everything's working fine now!