How much server ram does a variable consume?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hokiecsgrad
Forum Newbie
Posts: 17
Joined: Fri Oct 22, 2004 2:55 pm

How much server ram does a variable consume?

Post 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!!!
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post 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.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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!
Post Reply