Thanks WeedPacket. I went to php.net and searched for that function and found that it doesn't work because I need version 4.3.2. However, there was a message posted at the bottom providing a way to get the percentage of memory used by the Apache process.
I went ahead and tweaked it a little and created a function that will return the amount of memory used (not percentage) in KBytes. Here it is:
/*
This function will automatically select the Apache
process id, or which ever web service you are using.
If you want to specify the process id, you can do so
by sending it the id number in the function call.
*/
function memory_usage($pid = "") {
if ($pid == "")
$pid = getmypid();
exec("ps -eo rss,pid | grep $pid",$output);
return strtok(trim($output[0])," ");
}
/*
To use this properly, call it at the beginning of your script and at the end.
Then take the difference between the two values and that is the total amount
of memory used by your script.
Ex.
*/
$starting_amount = memory_usage();
// your script here...
$ending_amount = memory_usage();
echo "Total Memory Used by this script: ".($ending_amount - $starting_amount)." KBytes";
This function will only work in UNIX/Linux.
I'm experiencing only one problem with this function. If I hit refresh on my browser enough times, then Apache will stop "growing" in size. The difference of the starting amount and the ending amount will be zero. I think it has something to do with caching, but I'm not sure.
I do not know if this will work for everyone. If you have any suggestions, please post them here.
Thank you.
Rubric