PHP System Load on Mac OS X


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/usr/bin/php
  2. <?php
  3.  
  4. // This works with Mac OS X `uptime`
  5. // others might require tweaks
  6.  
  7. error_reporting( E_ALL );
  8.  
  9. function load()
  10. {
  11. $array = explode( ',', trim( `uptime` ) );
  12.  
  13. while( list( , $value ) = each( $array ) )
  14. {
  15. if( eregi( 'load', $value ) )
  16. {
  17. $parts = explode( ':', trim( $value ) );
  18.  
  19. $loads = explode( ' ', $parts[ count( $parts ) - 1 ] );
  20.  
  21. $load = $loads[ 1 ];
  22.  
  23. break;
  24. }
  25. }
  26.  
  27. return $load;
  28. }
  29.  
  30. echo load();
  31.  
  32. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.