note 64156 added to function.memory-get-usage
| From: | e dot a dot schultz at gmail dot com | Date: | Sat, 08 Apr 2006 23:41:44 +0000 |
| Subject: | note 64156 added to function.memory-get-usage | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107574@lists.php.net to get a copy of this message | ||
This is a function that should work for both Windows XP/2003 and most distrabutions of UNIX and Mac
OS X.
<?php
if( !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;
}
}
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 24.72.197.162
----
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/64156
Del: integrated -- http://master.php.net/note/delete/64156/integrated
Del: useless -- http://master.php.net/note/delete/64156/useless
Del: bad code -- http://master.php.net/note/delete/64156/bad+code
Del: spam -- http://master.php.net/note/delete/64156/spam
Del: non-english -- http://master.php.net/note/delete/64156/non-english
Del: in docs -- http://master.php.net/note/delete/64156/in+docs
Del: other reasons-- http://master.php.net/note/delete/64156
Reject -- http://master.php.net/note/reject/64156
Search -- http://master.php.net/manage/user-notes.php