Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Sprawdzanie czy dany host jest online
TNT
post
Post #1





Grupa: Zarejestrowani
Postów: 41
Pomógł: 2
Dołączył: 14.04.2007

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


Witam, posiadam stronę internetową oraz serwer gry Soldat. Otóż chciałbym umieścić na swojej stronie skrypt wyświetlający czy mój serwer jest online bądź offline. Aktualnie posiadam taki, ale gdy serwer jest wyłączony, ów skrypt powoduje zmniejszenie szybkości strony do minimum:

  1. <?php
  2. $host = array('blah.selfip.net'); 
  3. $port = array('23073'); 
  4.  
  5. foreach($host as $key => $value) 
  6. { 
  7. $fp = @fsockopen($value, $port[$key]); 
  8. echo 'Server is '; 
  9. if($fp) 
  10. { 
  11. echo '<b><span style="color: green">online</span></b>'; 
  12. } 
  13. else 
  14. { 
  15. echo '<b><span style="color: red">offline</span></b>'; 
  16. } 
  17. echo '<br/>'; 
  18. }
  19. echo '<b><a title="soldat climbing" href="soldat://blah.selfip.net:23073/">Click here to join</a></b>  ';
  20. ?>


Czy mógłby mi ktoś udostępnić skrypt nie obciążający strony gdy serwer jest offline?

Ten post edytował TNT 14.04.2007, 15:05:40
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
TNT
post
Post #2





Grupa: Zarejestrowani
Postów: 41
Pomógł: 2
Dołączył: 14.04.2007

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


OK, działa. Wielkie dzięki (IMG:http://forum.php.pl/style_emoticons/default/cool.gif)

Jeszcze jedno pytanie:
Gdzie wstawić ip i port w tym skrypcie:

  1. <?php
  2. // PHP ASE parser for Soldat by FliesLikeABrick
  3. // May be used for other games with a few slight modifications
  4. // (mainly removing the part that pretties up the output)
  5. // You are free to use this code for anything you want and redistribute/modify at will
  6.  
  7. function readASEString($sock,$length = false) {
  8. $length = $length ? $length : ord(fread($sock,1));
  9. return fread($sock,$length-1);
  10. }
  11.  
  12. function ASE($host,$port) {
  13. $info = Array();
  14. $s = fsockopen("udp://$host",$port+123);
  15. fwrite($s,"s");
  16. fread($s,4);
  17. readASEString($s);
  18. $info['port'] = readASEString($s);
  19. $info['servername'] = readASEString($s);
  20. $info['ip'] = gethostbyname($host);
  21. $info['mode'] = readASEString($s);
  22. $info['map'] = readASEString($s);
  23. $info['version'] = readASEString($s);
  24. $info['passworded'] = readASEString($s);
  25. $info['numplayers'] = readASEString($s);
  26. $info['maxplayers'] = readASEString($s);
  27.  
  28. // prime the loop conditional
  29. $lengthstring = fread($s,1);
  30. $length = ord($lengthstring);
  31.  
  32. // loop through the key/value pairs and set them
  33.  
  34. while($length != 1) {
  35. $info[readASEString($s,$length)] = readASEString($s);
  36. $lengthstring = fread($s,1);
  37. $length = ord($lengthstring);
  38. }
  39.  
  40. // this entire section can be removed if you don't use them
  41. $info['survival'] = $info['Survival'] == 'No' ? false:true;
  42. $info['realistic'] = $info['Realistic'] == 'No' ? false:true;
  43. $info['remaining'] = explode(' ',$info['Time Left']);
  44. $info['remaining'] = $info['remaining'][0];
  45. $info['minutes'] = explode(':',$info['remaining']);
  46. $info['seconds'] = $info['minutes'][1];
  47. $info['minutes'] = $info['minutes'][0];
  48. $info['timelimit'] = explode(' ',$info['Time Limit']);
  49. $info['timelimit'] = $info['timelimit'][0];
  50. $info['protected'] = $info['Protected'] == 'No' ? false:true;
  51. // end removable section
  52.  
  53. $info['players'] = Array();
  54. for($i=0;$i<$info['numplayers'];$i++) {
  55. $info['players'][$i] = Array();
  56. fread($s,1);
  57. $info['players'][$i]['name'] = readASEString($s);
  58. $info['players'][$i]['team'] = readASEString($s);
  59. $info['players'][$i]['skin'] = readASEString($s);
  60. $info['players'][$i]['score'] = readASEString($s);
  61. $info['players'][$i]['ping'] = readASEString($s);
  62. $info['players'][$i]['time'] = readASEString($s);
  63. }
  64. return $info;
  65. }
  66.  
  67. ?>


O tak?
Oryginał:
$s = fsockopen("udp://$host",$port+123);

Po podstawieniu ip i portu:
$s = fsockopen("udp://blah.selfip.net",23073+123);

Ten post edytował TNT 15.04.2007, 12:50:27
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: 27.12.2025 - 22:15