login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Serverload

Offline stuifie - 24/05/2005 22:12
Avatar van stuifiePHP beginner Weet er iemand of het mogelijk is om de serverload te bekijken met een script?
heb al gezocht maar kon niet echt iets vinden

2 antwoorden

Gesponsorde links
Offline EclipX - 24/05/2005 23:00
Avatar van EclipX Lid Ik ben het niet zéker, heb effe gegoogeld:

  1. <?PHP
  2.  
  3. function serverload() {
  4.  
  5. // Use:x
  6. // INCLUDE the file in your script (or cut and paste in)
  7. // assign to a variable $serverload = serverload();
  8. // This will ONLY track page counts from pages that call the
  9. // serverload() function. If you want a page counted, but do
  10. // not need the results, simply call the function without
  11. // assigning a variable.
  12. //
  13. // Requirements:
  14. // MySQL database set up with a table (user selectable) in a
  15. // database (user selectable). Table has one field, time, which
  16. // is defined as INT(14) type.
  17.  
  18. // Define variables
  19.  
  20. $database = "_nuke"; // Name of MySQL database
  21. $hostname = "localhost"; // Name of database server
  22. $username = "Paul Laudanski"; // MySQL user
  23. $password = "Chris Mospaw"; // Password for user
  24. $tablename = "nuke_serverload"; // Table in database above that
  25. information is stored in
  26.  
  27. $duration = "300"; // How many seconds load will represent.
  28.  
  29. // Open MySQL connection and database
  30. mysql_connect($hostname,$username,$password) or
  31. die ( "Could not connet to MySQL" );
  32. mysql_select_db($database) or
  33. die ( "Could not connect to database" );
  34.  
  35. // Delete old page counts
  36. $sql = "DELETE FROM $tablename WHERE time < " . (time()-$duration);
  37. $result = mysql_query($sql) or
  38. die ("Error:" . mysql_error() );
  39. // Insert the current page count
  40.  
  41. $sql = "INSERT INTO $tablename (time) VALUES (" . time() . ") ";
  42.  
  43. $result = mysql_query($sql) or
  44. die ("Error:" . mysql_error() );
  45. // Get page count (number of rows in the table)
  46.  
  47. $sql = "SELECT time FROM $tablename";
  48.  
  49. $result = mysql_query($sql) or
  50. die ("Error:" . mysql_error() );
  51.  
  52. return mysql_num_rows ($result);
  53.  
  54. } // END FUNCTION serverload
  55.  
  56. ?>
Offline Frederic - 24/05/2005 23:13 (laatste wijziging 25/05/2005 18:31)
Avatar van Frederic PHP ver gevorderde Ik zal de komende dagen een script posten hier op SiMa hoe het te berekenen!

//EDIT: staat bij PHP-Handige scripts
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.213s