Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] cache status serwerów
Duo
post
Post #1





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 16.11.2010

Ostrzeżenie: (0%)
-----


Witam !
Kombinuję sobie, jak połączyć cache ze statusem serwer, tak aby status odświeżał się co 30 sekund, więc tak aktualnie to statusik pojawia się za pierwszym razem, po odświeżeniu pojawia się link do statusu. 1 wejście obrazek, potem http://www.efrags.pl/status/cs/ffa.efrags.pl:27015.png, a nie obrazek. (IMG:style_emoticons/default/worriedsmiley.gif) Proszę nie krzyczeć, że coś źle bo jestem zielony, chciałem połączyć dwa skrypty ze sobą ale coś trochę nie wyszło.

To co wyskrobałem:

  1. <?php
  2. /*
  3. *
  4. * Graficzny status serwerow, oparty o biblioteke GameQ ( http://gameq.sourceforge.net/ )
  5. * Copyright 2010 by Fragles.eu
  6. * Nie zezwalam na sprzedawanie tego skryptu, o czym mowi rowniez licencja GNU
  7. *
  8. */
  9.  
  10. require_once 'GameQ.php';
  11.  
  12. // przykladowe czcionki
  13. define('TEMPESTA', 'status/fonts/tempesta.ttf');
  14. define('TAHOMA', 'status/fonts/tahoma.ttf');
  15. define('VERDANA', 'status/fonts/verdana.ttf');
  16. define('TAHOMA_BOLD', 'status/fonts/tahoma_bold.ttf');
  17.  
  18. // przyporządkowujemy zmienna do zmiennej globalnej
  19. $server = $_GET['server'];
  20. $game = $_GET['game'];
  21. $cachefile = "./cache/server_".$_SERVER['QUERY_STRING'].$ext;
  22. $cachefile = str_replace(':', '-', $cachefile);
  23.  
  24. $cachetime = 30; //czas cache'owania
  25.  
  26. // cachowanie
  27. if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile)))
  28. {
  29. send_headers();
  30. echo file_get_contents($cachefile);
  31. }
  32. // Jesli nie podano ip lub gry
  33. if (isset($server) && !empty($server) && isset($game) && !empty($game))
  34. {
  35. // podzielenie adresu na ip oraz port
  36. list($ip, $port) = explode(":", $server);
  37.  
  38. $gq = new GameQ();
  39. // dodajemy serwer
  40. $gq->addServer('serwer', array($game, $ip, $port));
  41. $gq->setOption('timeout', 200);
  42. $gq->setFilter('normalise');
  43. $gq->setFilter('sortplayers', 'gq_ping');
  44. $results = $gq->requestData();
  45.  
  46. /**
  47. * rozpatrujemy dwa przypadki
  48. * 1 - serwer offline bo nie ma nazwy serwera
  49. * 2 - serwer online
  50. */
  51. if($results['serwer']['gq_hostname']=="")
  52. {
  53. $hostname = "Serwer OFFLINE";
  54. $players = "x";
  55. $playersmax = "x";
  56. $map = "Offline";
  57. }
  58. else
  59. {
  60. $hostname = $results['serwer']['gq_hostname'];
  61. $players = $results['serwer']['gq_numplayers'];
  62. $playersmax = $results['serwer']['gq_maxplayers'];
  63. $map = $results['serwer']['gq_mapname'];
  64. }
  65.  
  66. // utworzenie obrazka z tla
  67. $im = imagecreatefrompng("status/bg.png");
  68. // kolor bialy
  69. $white = imagecolorallocate($im, 255, 255, 255);
  70. // polaczenie informacji do jednej zmiennej
  71. $info = $server ." ". $players ." / ". $playersmax ." ". $map;
  72. // gorny rzad, nazwa serwera
  73. imagettftext($im, 7, 0, 30, 10, $white, VERDANA, $hostname);
  74. // dolny rzad, ip serwera, gracze, mapa
  75. imagettftext($im, 7, 0, 30, 21, $white, VERDANA, $info);
  76.  
  77. // nie podano adresu w zmiennej $_GET
  78. } else {
  79. $im = imagecreatefrompng("status/background.png");
  80. $white = imagecolorallocate($im, 255, 255, 255);
  81. $info = "xx.xxx.xxx:xxxxx xx / xx OFFLINE";
  82. imagettftext($im, 7, 0, 30, 10, $white, VERDANA, "Serwer OFFLINE");
  83. imagettftext($im, 7, 0, 30, 21, $white, VERDANA, $info);
  84. }
  85.  
  86. function send_headers() {
  87. global $config;
  88. if($ext == '.png') {
  89. header ('Content-type: image/png');
  90. } else {
  91. header ('Content-type: image/jpeg');
  92. }
  93. }
  94.  
  95. // okreslenie typu zawartosci
  96. header('Content-type: image/png');
  97. imagepng($im);
  98. imagedestroy($im);
  99. $fp = fopen($cachefile, 'wb');
  100. fclose($fp);
  101. ?>


refresh

Ten post edytował Duo 16.11.2010, 21:44:46
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 00:51