note 54758 modified in function.memory-get-usage by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 00:48:42 +0000 |
| Subject: | note 54758 modified in function.memory-get-usage by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141864@lists.php.net to get a copy of this message | ||
[EDIT by danbrown AT php DOT net: This function will only extend Windows versions of PHP where the
server has the required third-party software.]
I was unable to get the previous examples working properly and created code which works at least for
me. Enjoy!
<?php
// Please note that you'll need the pslist.exe utility from http://www.sysinternals.com/Utilities/PsTools.html
// This is because win/2000 itself does not provide a task list utility.
//
function getMemoryUsage() {
// try to use PHP build in function
if( function_exists('memory_get_usage') ) {
return memory_get_usage();
}
// Try to get Windows memory usage via pslist command
if ( substr(PHP_OS,0,3) == 'WIN') {
$resultRow = 8;
$resultRowItemStartPosition = 34;
$resultRowItemLength = 8;
$output = array();
exec('pslist -m ' . getmypid() , $output);
return trim(substr($output[$resultRow], $resultRowItemStartPosition, $resultRowItemLength)) .
' KB';
}
// No memory functionality available at all
return '<b style="color: red;">no value</b>';
}
?>
--was--
I was unable to get the previous examples working properly and created code which works at least for
me. Enjoy!
// Please note that you'll need the pslist.exe utility from http://www.sysinternals.com/Utilities/PsTools.html
// This is because win/2000 itself does not provide a task list utility.
//
function getMemoryUsage() {
// try to use PHP build in function
if( function_exists('memory_get_usage') ) {
return memory_get_usage();
}
// Try to get Windows memory usage via pslist command
if ( substr(PHP_OS,0,3) == 'WIN') {
$resultRow = 8;
$resultRowItemStartPosition = 34;
$resultRowItemLength = 8;
$output = array();
exec('pslist -m ' . getmypid() , $output);
return trim(substr($output[$resultRow], $resultRowItemStartPosition, $resultRowItemLength)) .
' KB';
}
// No memory functionality available at all
return '<b style="color: red;">no value</b>';
}
http://php.net/manual/en/function.memory-get-usage.php