Page 1 of 1

How much server ram does a variable consume?

Posted: Fri Oct 22, 2004 2:59 pm
by hokiecsgrad
Greetings,

I'm trying to figure out if there's a way in PHP to figure out how much RAM a particular variable is consuming at any given time. More specifically, I want to know how much RAM an entire structure is using.

Basically, I'm in a position where I know I can't use more than 1.5MB of RAM and I'm trying to sort a VERY large data set. I'm using an external sort, but I want to know how many records I can load into RAM and sort at any given point. Thanks for the help!!!

Posted: Fri Oct 22, 2004 5:26 pm
by Steveo31
The only thing I can think of is to edit your ini file and alter this:

Code: Select all

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60	; Maximum amount of time each script may spend parsing request data
memory_limit = 8M      ; Maximum amount of memory a script may consume (8MB)
To 1.5.

Posted: Fri Oct 22, 2004 5:37 pm
by rehfeld

Posted: Fri Oct 22, 2004 5:39 pm
by John Cartwright
To get this in pre 4.2.3 do a (works on unix like systems only):

$my_pid = getmypid();
error_log("MEMORY USAGE (% KB PID ): ".`ps -eo%mem,rss,pid | grep $my_pid`);

found this tip somewhere in bugs.php.net!