All pastes #341035 Raw Edit

Anonymous

public php v1 · immutable
·published 2007-02-05 06:50 UTC
rendered paste body
<?phpif( !function_exists('memory_get_usage') ){   function memory_get_usage()   {       //If its Windows       //Tested on Win XP Pro SP2. Should work on Win 2003 Server too       //Doesn't work for 2000       //If you need it to work for 2000 look at http://us2.php.net/manual/en/function.memory-get-usage.php#54642       if ( substr(PHP_OS,0,3) == 'WIN')       {               if ( substr( PHP_OS, 0, 3 ) == 'WIN' )               {                   $output = array();                   exec( 'tasklist /FI "PID eq ' . getmypid() . '" /FO LIST', $output );                         return preg_replace( '/[\D]/', '', $output[5] ) * 1024;               }       }else       {           //We now assume the OS is UNIX           //Tested on Mac OS X 10.4.6 and Linux Red Hat Enterprise 4           //This should work on most UNIX systems           $pid = getmypid();           exec("ps -eo%mem,rss,pid | grep $pid", $output);           $output = explode("  ", $output[0]);           //rss is given in 1024 byte units           return $output[1] * 1024;       }   }}$b=memory_get_usage();$b=memory_get_usage();$b=memory_get_usage();$b=memory_get_usage();$b=memory_get_usage();$b=memory_get_usage();//-------------//Ignore that multiple loops//Its only to have CLEAN memory_usage because of exec$b=memory_get_usage();function flood(){for($i=0;$i<1000;$i++)$a[$i]=new StdClass;} flood();echo "Start:$b #1 Memory Usage:".number_format((memory_get_usage() - $b) / 1024, 2) . "KB\n";flood();echo "Start:$b #2 Memory Usage:".number_format((memory_get_usage() - $b) / 1024, 2) . "KB\n";flood();echo "Start:$b #3 Memory Usage:".number_format((memory_get_usage() - $b) / 1024, 2) . "KB\n";flood();echo "Start:$b #4 Memory Usage:".number_format((memory_get_usage() - $b) / 1024, 2) . "KB\n";flood();echo "Start:$b #5 Memory Usage:".number_format((memory_get_usage() - $b) / 1024, 2) . "KB\n";/*X:\>php -f mem.phpStart:13619200 #1 Memory Usage:128.00KBStart:13619200 #2 Memory Usage:180.00KBStart:13619200 #3 Memory Usage:184.00KBStart:13619200 #4 Memory Usage:184.00KBStart:13619200 #5 Memory Usage:188.00KB*/?>