You are here: Re: memory usage « All PHP « IT news, forums, messages
Re: memory usage

Posted by kmatheeswar on 08/17/06 14:56

Check out whether this function is useful. But it will return the memory
used currently by the php script, not the free memory
<?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;
}
}
}
echo memory_get_usage();
?>


--
kmatheeswar
------------------------------------------------------------------------
kmatheeswar's Profile: http://techiegroups.com/member.php?userid=205
View this thread: http://www.techiegroups.com/showthread.php?t=114709

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация