Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I monitor memory usage of php in linux?

Tags:

I have used valgrinds massif tool to monitor memory usage in the past.

Does anyone know how to capture memory use of php processes that are spawned on a linux lighttpd server?

I have found that Valgrind can not attach to a prerunning process (and I would not know the PID of the php process before hand anyway)

I only see lighttpd's memory usage, not the PHP processes that are spawned by lighttpd cgi module.

Thanks in advance.

like image 243
DEzra Avatar asked Jul 02 '09 07:07

DEzra


People also ask

How do I check my PHP memory limit?

An attacker can view the memory limit set by executing phpinfo() function to see the memory limit and plan an attack according to the value. A server administrator can set memory limit from -1 (No memory allocation) to any size. The memory limit was first introduced as a setting in php.

How can I get CPU and memory usage in PHP?

To get the current memory usage, we can use the memory_get_usage() function, and to get the highest amount of memory used at any point, we can use the memory_get_peak_usage() function.

How much memory does each PHP process consume?

When I set the PHP memory limit to e.g. 128 MB for each of these daemons, the processes will only get killed once they reach 128 MB according to PHP's own measurements. However, according to ps , the processes will be using around 200 MB each by that time.


1 Answers

PHP has it's own memory testing functions, I don't know if that's any use to you, but if you just want to log it you could use: http://php.net/manual/en/function.memory-get-peak-usage.php

    echo "Using ", memory_get_peak_usage(1), " bytes of ram.";
like image 143
scragar Avatar answered Sep 24 '22 13:09

scragar