Jak w temacie szukam czegoś takiego że bedzie sprawdzaiło działanie serwera od jakiegoś czasu.
Przykład:
-Sprawdza datę rozpoczęcia np w pliku (12:00)
-I odejmuje czas rozpoczęcia od teraźniejszego.

I wyskoczy np :
Uptime: 09:34
ale bedzie sie zmieniało samo co 1min

Mój coś nie chce działać"

  1. <?php
  2.  
  3. function getinfo($host='94.23.150.254',$port=21){
  4. // connects to server
  5. $socket = @fsockopen($host, $port, $errorCode, $errorString, 1);
  6. $data = '';
  7. // if connected then checking statistics
  8. if($socket)
  9. {
  10. // sets 1 second timeout for reading and writing
  11. stream_set_timeout($socket, 1);
  12.  
  13. // sends packet with request
  14. // 06 - length of packet, 255, 255 is the comamnd identifier, 'info' is a request
  15. fwrite($socket, chr(6).chr(0).chr(255).chr(255).'info');
  16.  
  17. // reads respond
  18. while (!feof($socket)){
  19. $data .= fread($socket, 128);
  20. }
  21.  
  22. // closing connection to current server
  23. fclose($socket);
  24. }
  25. return $data;
  26. }
  27. if ($cfg['status_update_interval'] < 60) $cfg['status_update_interval'] = 60;
  28. $modtime = filemtime('status.xml');
  29. if (time() - $modtime > $cfg['status_update_interval'] || $modtime > time()){
  30. $info = getinfo($cfg['server_ip'], $cfg['server_port']);
  31. if (!empty($info)) file_put_contents('status.xml',$info);
  32. }else $info = file_get_contents('status.xml');
  33. if (!empty($info)) {
  34. $infoXML = simplexml_load_string($info);
  35.  
  36. $up = (int)$infoXML->serverinfo['uptime'];
  37.  
  38. $h = floor($up/3600);
  39. $up = $up - $h*3600;
  40. $m = floor($up/60);
  41. $up = $up - $m*60;
  42. if ($h < 10) {$h = "0".$h;}
  43. if ($m < 10) {$m = "0".$m;}
  44. echo "<span class=\"online\">Online</span><br/>\n";
  45. echo "<span class=\"uptime\">Uptime: <b>$h:$m</b></span><br/>\n";
  46. } else {
  47. echo "<span class=\"offline\">Offline</span>\n";
  48. }
  49. ?>

XML:
  1. <?xml version="1.0"?>
  2. <serverinfo uptime="0" ip="94.23.150.254" port="21" />