Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Status servera problem, Skrypt sprawdza port 80 a nie 20100
adamshl
post
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 3.01.2005

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


Witam wszystkich, mam taki skrypt:

  1. <?php 
  2.  $fp = @fsockopen(&#092;"udp://adam\", 20100, &$errno, &$errstr); 
  3.  if (!$fp) { 
  4. echo(&#092;"<span style=\"font-weight: bold;\">Server status: <span style='color:red'>Offline</span></span>\"); 
  5.  } else { 
  6. echo(&#092;"<span style=\"font-weight: bold;\">Server status: <span style='color:green'>Online</span></span>\"); 
  7. fclose ($fp); 
  8.  } 
  9. ?>


i chcialbym sprawdzic np. czy na porcie 20100 stoji serwer gry, ale jest problem bo ten skrypt sprawdza caly czas port 80 mimo to ze ustawilem port 20100 no chyba ze w tym miejscu nie podaje sie portu tylko np. jakies opuznienie ile skrypt ma czekac na polaczenie... hmm kto pomoze rozwiazc ten problem ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 10)
tiraeth
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 789
Pomógł: 41
Dołączył: 30.10.2003
Skąd: Wrocław

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


  1. <?
  2. echo &#092;"<b>\".&$errno.\"</b>: \".&$errstr;
  3. ?>


dodaj to na końcu.... i usuń małpę przed fsockopen.... i zobacz co wywala.... prawdopodobnie wywali, że port jest zamknięty czy coś w tym rodzaju...
Go to the top of the page
+Quote Post
adamshl
post
Post #3





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 3.01.2005

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


zrobilem to po twojemu:
  1. <?php
  2.  
  3.  $fp = fsockopen(&#092;"udp://adam\", 20100, &$errno, &$errstr); 
  4.  if (!$fp) { 
  5. echo(&#092;"<span style=\"font-weight: bold;\">Server status: <span style='color:red'>Offline</span></span>\"); 
  6.  } else { 
  7. echo(&#092;"<span style=\"font-weight: bold;\">Server status: <span style='color:green'>Online</span></span>\"); 
  8. fclose ($fp); 
  9.  } 
  10.  echo &#092;"<b>\".&$errno.\"</b>: \".&$errstr;
  11.  
  12. ?>


i nic nie wywala, czysta strona.

pozatym troszke zle zrozumiales, nie wywali napewno ze port jest zamkniety bo skrypt mimo ze wisalem 20100 sprawdza port 80 a na tym porcie stoji WWW, a ja nie wiem jak ustawic zeby sprawdzal wlasnie ten port: 20100
Go to the top of the page
+Quote Post
tiraeth
post
Post #4





Grupa: Przyjaciele php.pl
Postów: 1 789
Pomógł: 41
Dołączył: 30.10.2003
Skąd: Wrocław

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


Cytat(Manual / fsockopen)
UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable.

czyli jeżeli użyjesz np. udp://adam to nie zwróci żadnego błędu.... dlatego nie wywala błędu i sprawdza port 80 gdyż jest on domyślny smile.gif

spróbuj zamiast udp dać tcp....
Go to the top of the page
+Quote Post
adamshl
post
Post #5





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 3.01.2005

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


cholera.... probowalem na rozne sposoby i dalej nic sadsmiley02.gif
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #6





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


Nie przekazuj parametrow w ten sposob:
funkcja( &$paramatr )
tylko:
funkcja( $paramatr )

I masz
Cytat
Parse error: parse error, unexpected '&' in (...) on line 10

tzn tu:
  1. <?php
  2. echo &#092;"<b>\".&$errno.\"</b>: \".&$errstr;
  3. ?>

Wlacz sobie wyswietlanie bledow!!!
error_reporting( E_ALL );

zobaczysz tez cos takiego:
Cytat
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in(...) on line 4

tj:
  1. <?php
  2.  $fp = fsockopen(&#092;"udp://adam\", 20100, $errno, $errstr); 
  3. // 
  4. sprobuj uzyc adresu IP zamiast nazwy 'adam'
  5.  
  6. ?>


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
adamshl
post
Post #7





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 3.01.2005

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


po adresie IP tez probowalem i tez nic z tego sad.gif
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #8





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


Pelny cytat:
Cytat
UDP sockets will sometimes appear to have opened without an error, even if the remote host is unreachable. The error will only become apparent when you read or write data to/from the socket. The reason for this is because UDP is a "connectionless" protocol, which means that the operating system does not try to establish a link for the socket until it actually needs to send or receive data.


UDP jest BEZPOLACZENIOWYM protokolem (w odroznieniu od TCP) -- nie nawiazuje polaczenia, wiec nie moze zwrocic bool'a wskazujacego czy udalo sie odtworzyc polaczenie (dlatego zwraca TRUE, zeby nie przerwac kolejnych operacji odczytu zapisu na tym strumieniu), tzn jak robisz fsockopen() to php zapamietuje parametry polaczenia (ip, port) i dopiero przy wysylaniu/odbieraniu danych (fread, fwrite,...) tworzy "link" (nie polaczenie), wysyla dane i sprawdza czy dotarly, i dopiero tu moze wystapic error. Sproboj odczytac/wyslac jakies dane pod ten adres i sprawdzic rezultat tej operacji.

Cytat
Note that with UDP there is no handshaking between sending and receiving transport-layer entities before sending a segment. For this reason, UDP is said to be connectionless.


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
adamshl
post
Post #9





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 3.01.2005

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


Znalazlem inny fajny skrypcik ale jest maly problem bo on wyswietla satus serwera graficznie a mi wystarczy status tekstowy, probowalem juz na kilka sposobow go przerobbic ale mi cos nie wychodzi.

  1. <?php
  2. //Location of the live or dead server images
  3.  
  4. //Please change to your server specifications
  5. $live = &#092;"online.PNG\";
  6. $dead = &#092;"offline.PNG\";
  7.  
  8. //The status checking script
  9. //meddle at your own risk!
  10. //check for port number, default is 80
  11. $link = $_GET['link'].&#092;":\";
  12. $s_link = str_replace(&#092;"::\", \":\", $link);
  13. list($addr,$port)= explode (':',&#092;"$s_link\");
  14. if (empty($port)){
  15.     $port = 80;
  16. }
  17. //Test the server connection
  18. $churl = @fsockopen(server($addr), $port, $errno, $errstr, 15);
  19.              if (!$churl){
  20.              //echo $errstr;
  21.                 header(&#092;"Location: $dead\");
  22.                 }
  23.              else {
  24.                    header(&#092;"Location: $live\");             
  25.           }
  26. function server($addr){
  27.          if(strstr($addr,&#092;"/\")){$addr = substr($addr, 0, strpos($addr, \"/\"));}
  28.          return $addr;
  29. }
  30. ?>


Sprobowal by ktos przerobic ten skrypt tak aby wyswietlal status tekstowy np. Online, Offline ?

do skryptu odwoluje sie za pomoca linku. tenskrypt.php?link=o2.pl

Ten post edytował adamshl 11.01.2005, 19:15:34
Go to the top of the page
+Quote Post
tiraeth
post
Post #10





Grupa: Przyjaciele php.pl
Postów: 1 789
Pomógł: 41
Dołączył: 30.10.2003
Skąd: Wrocław

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


  1. <?php
  2. // Zdeklarowanie funkcji przenosimy na poczatek
  3. function server($addr)
  4. {
  5.  if(strstr($addr,&#092;"/\"))
  6.  {
  7. $addr = substr($addr, 0, strpos($addr, &#092;"/\"));
  8.  }
  9.  return $addr;
  10. }
  11.  
  12. // Ustawiamy string'i dla online i offline
  13. $live = 'Serwer jest <span style=\"color:green;\"><b>ONLINE<b></span>'; // ONLINE
  14. $dead = 'Serwer jest <span style=\"color:red;\"><b>OFFLINE</b></span>'; // OFFLINE
  15.  
  16. $link = $_GET['link'].&#092;":\";
  17. $s_link = str_replace(&#092;"::\", \":\", $link);
  18. list($addr,$s_port) = explode(':',&#092;"$s_link\");
  19.  
  20. $port = ($s_port) ? $s_port : 80;
  21.  
  22. $churl = @fsockopen(server($addr), $port, $errno, $errstr, 15);
  23.  
  24. echo (!$churl) ? $dead.' (<b>'.$errno.'</b>: '.$errstr.')' : $live;
  25. ?>
Go to the top of the page
+Quote Post
adamshl
post
Post #11





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 3.01.2005

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


Wielkie Dzieki Tiraeth smile.gif

tylko teraz mam nastepny problem bo nie wiem jak wynik wklejic do index.php

wczesniej byl wynik graficzny to robilem to tak:
  1. <?php
  2. <img src=&#092;"status.php?link=o2.pl\" width=\"60\" height=\"16\">
  3. ?>


a teraz jak ja mam to zrobic ? probowalem includnac

  1. <?php include(&#092;"status.php?link=elitetorrents.org\") ?>
ale nie dziala, wywala error.
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 21.08.2025 - 06:06