Posted By

gdonald on 11/28/06


Tagged

php mac load from uptime


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

willcodeforfood
AllKnightAccess


PHP System Load on Mac OS X


 / Published in: PHP
 

  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  

You need to login to post a comment.