Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file function.memusage.php

Documentation is available at function.memusage.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8. /**
  9.  * smarty_function_memusage
  10.  */
  11. function smarty_function_memusage($params&$gBitSmarty{
  12.     iffunction_exists'memory_get_usage' ) ) {
  13.         $memusage memory_get_usage();
  14.     else {
  15.         // If its Windows
  16.         // Tested on Win XP Pro SP2. Should work on Win 2003 Server too
  17.         // Doesn't work for 2000
  18.         // If you need it to work for 2000 look at http://us2.php.net/manual/en/function.memory-get-usage.php#54642
  19.         ifsubstrPHP_OS0== 'WIN' {
  20.             ifsubstrPHP_OS0== 'WIN' {
  21.                 $output array();
  22.             }
  23.             exec'tasklist /FI "PID eq ' getmypid('" /FO LIST'$output );
  24.             $memusage preg_replace'/[\D]/'''$output[51024;
  25.         else {
  26.             // We now assume the OS is UNIX
  27.             // Tested on Mac OS X 10.4.6 and Linux Red Hat Enterprise 4
  28.             // This should work on most UNIX systems
  29.             $pid getmypid();
  30.             exec"ps -eo%mem,rss,pid | grep $pid"$output );
  31.             $output explode" "trim$output[0) );
  32.             // rss is given in 1024 byte units
  33.             $memusage $output[11024;
  34.         }
  35.     }
  36.  
  37.     if$memusage {
  38.         $memunit="B";
  39.         if$memusage 1024 {
  40.             $memusage $memusage/1024;
  41.             $memunit "kB";
  42.         }
  43.         if$memusage>1024 {
  44.             $memusage=$memusage/1024;
  45.             $memunit="MB";
  46.         }
  47.         if$memusage>1024 {
  48.             $memusage=$memusage/1024;
  49.             $memunit="GB";
  50.         }
  51.         printnumber_format$memusage).$memunit );
  52.     }
  53. }
  54.  
  55. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:39 +0000 by phpDocumentor 1.5.0-lsces