How can I monitor memory usage of php in linux?

memory, php, valgrind

Solution

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.";

Problem

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.

Original source