note 63895 added to function.memory-get-usage

From: Date: Mon, 03 Apr 2006 13:02:59 +0000
Subject: note 63895 added to function.memory-get-usage
Groups: php.notes 
Request: Send a blank email to php-notes+get-107224@lists.php.net to get a copy of this message
<?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 ---- Server IP: 194.109.193.119 Probable Submitter: 82.74.107.91 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.memory-get-usage.php Edit -- http://master.php.net/note/edit/63895 Del: integrated -- http://master.php.net/note/delete/63895/integrated Del: useless -- http://master.php.net/note/delete/63895/useless Del: bad code -- http://master.php.net/note/delete/63895/bad+code Del: spam -- http://master.php.net/note/delete/63895/spam Del: non-english -- http://master.php.net/note/delete/63895/non-english Del: in docs -- http://master.php.net/note/delete/63895/in+docs Del: other reasons-- http://master.php.net/note/delete/63895 Reject -- http://master.php.net/note/reject/63895 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107224) next »