note 63895 deleted from function.memory-get-usage by danbrown

From: Date: Wed, 26 Jan 2011 14:28:38 +0000
Subject: note 63895 deleted from function.memory-get-usage by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176340@lists.php.net to get a copy of this message
Note Submitter: xolox at home dot nl ---- <?php // Original from http://php.net/memory_get_usage by websjwans at hotmail dot com. Thanks alot! if ( ! function_exists( 'memory_get_usage' ) ): // Only define function if it doesn't exist function memory_get_usage() { // If we are running on Windows if ( substr( PHP_OS, 0, 3 ) == 'WIN' ): $output = array(); // Should check whether tasklist is available, but I'm lazy exec( 'tasklist /FI "PID eq ' . getmypid() . '" /FO LIST', $output ); // Filter non-numeric characters from output. Why not use substr & strpos? // I'm running Windows XP Pro Dutch, and it's output does not match the // English variant, as will all other translations. This is a more generic // approach, and has a better chance of actually working return preg_replace( '/[^0-9]/', '', $output[5] ) * 1024; // Tasklist outputs memory usage in kilobytes, memory_get_usage in bytes. // So we multiply by 1024 and in the process convert from string to integer. else: return false; endif; } endif; ?> Works for me. Functionality should match memory_get_usage(), albeit slower (exec & regex). Have fun! - Peter Odding

« previous php.notes (#176340) next »