Php – How to determine php memory usage on apache

apache-2.2memoryPHP

Sorry if I didn't phrase my question correctly.

I use the php function "memory_get_usage()" to see the amount memory allocated to PHP on a script I am running.

On server A I get around 2 MB. (CentOS 6, Apache 2.2.15)
The same script on server B I get around 1 MB. (Mac OSX, Apache 2.2.22)

Where should I check, or how should I fine tune my apache or php settings on server A to have similar memory footprint on server B?

For example, does the memory foot print affected by the loaded php extensions?

Best Answer

I guess different environments will cause a script to consume different amounts of memory. I'm fairly sure that the more extensions loaded the more memory PHP will consume, so using only the ones you need is advised. You should start by comparing the versions of PHP and which modules are installed on each server.

If you're looking to increate the amount of memory a script can consume:

http://php.net/manual/en/ini.core.php

memory_limit integer This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.

http://www.hostucan.com/webmaster-tutorials/increase-php-memory-limit

How much memory do I need?

It depends, for wordpress core, 32MB is the default memory limit. For drupal6 core, the min memory limit is 16MB, 32MB is recommended. But if you install many plugins, especially the plugins deal with image, you probably need 128MB or more memory.

There's not too much you can do config wise if you have a script that has inefficient code, if you'd like to get more bang for your buck, you should look to see if you can make the code more efficient so that it consume less memory.