Diskusijų forumai
Diskusijų forumai     Tinklalapių kūrimas ir programavimas     PHP/MySQL     Klaida su PHP funkcija fsockopen()



Klaida su PHP funkcija fsockopen()

bontavi
Naujokas

 
Busiu labai dekingas jai kas padesit sutvarkyt sita scripta(jai yra zinanciu).


1.    $file      = fsockopen ($domain, $portl, $errno, $errstr, 10);
2.    $file2      = fsockopen ($domain2, $portg1, $errno, $errstr, 10);
3.    $file3      = fsockopen ($domain3, $portg2, $errno, $errstr, 10);

Warning: fsockopen() [function.fsockopen]: unable to connect to :0 (Failed to parse address "") in /var/www/online.php on line 8

Login
Status: On
Stability: Great

Warning: fsockopen() [function.fsockopen]: unable to connect to :0 (Failed to parse address "") in /var/www/online.php on line 42

Elcardia(AvD)
Status: On
Stability: Great

Warning: fsockopen() [function.fsockopen]: unable to connect to :0 (Failed to parse address "") in /var/www/online.php on line 75

Elcardia(PvP)
Status: On
Stability: Great


scripto kodas:
<?php

$server = "xxx.xxx.xx.xxx";
$portl = "0000";

function pingDomain($server){
    $starttime = microtime(true);
    $file      = fsockopen ($domain, $portl, $errno, $errstr, 10);
    $stoptime  = microtime(true);
    $status    = 0;

    if (!$file) $status = -1;
    else {
        fclose($file);
        $status = ($stoptime - $starttime) * 12000;
        $status = floor($status);
    }
    return $status;
}      

        $status = pingDomain($serverbase);
        if ($status <= 50) $MessageStatus = "Great";
        elseif ($status <= 80) $MessageStatus = "Good";
        elseif ($status <= 100) $MessageStatus = "Ok";
        elseif ($status <= 150) $MessageStatus = "Bad";
        elseif ($status <= 999) $MessageStatus = "Poor";
        else $MessageStatus = "Disconnected";


$upmessage = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>$MessageStatus</font><br>";
$downmessage = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>Disconnected</font><br>";
$tout = "5";
$server1 = @fsockopen ($server, $portl, $errno, $errstr, $tout);
if(!$server1){ echo"<br><font color='C8B560' size='2' style='Arial'><strong>Login</strong></font><br><font size='1' color='black'>Status:</font><font color='red' size='1' style='Arial'> Off</font>$downmessage"; }
else { echo"<br><font color='C8B560' size='2' style='Arial'><strong>Login</strong></font><br><font size='1' color='black'>Status:</font><font color='green' size='1' style='Arial'> On</font>$upmessage"; }

$serverg1 = "xxx.xxx.xx.xxx";
$portg1 = "0000";

function pingDomain2($serverg1){
    $starttime2 = microtime(true);
    $file2      = fsockopen ($domain2, $portg1, $errno, $errstr, 10);
    $stoptime2  = microtime(true);
    $status2    = 0;

    if (!$fi1e2) $status2 = -1;
    else {
        fclose($file2);
        $status2 = ($stoptime2 - $starttime2) * 1000;
        $status2 = floor($status2);
    }
}      

        $status2 = pingDomain2($serverbase2);
        if ($status2 <= 50) $MessageStatus2 = "Great";
        elseif ($status2 <= 80) $MessageStatu2s2 = "G1ood";
        elseif ($status2 <= 100) $MessageStatus2 = "Ok";
        elseif ($status2 <= 150) $MessageStatus2 = "Bad";
        elseif ($status2 <= 999) $MessageStatus2 = "Poor";
        else $MessageStatus2 = "Disconnected";


$upmessage2 = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>$MessageStatus2</font><br>";
$downmessage2 = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>Disconnected</font><br>";
$tout = "5";
$serverg1 = @fsockopen ($serverg1, $portg1, $errno, $errstr, $tout);
if(!$serverg1){ echo"<br><font color='C8B560' size='2' style='Arial'><strong>Elcardia(AvD)</strong></font><br><font size='1' color='black'>Status:</font><font color='red' size='1' style='Arial'> Off</font>$downmessage2"; }
else { echo"<br><font color='C8B560' size='2' style='Arial'><strong>Elcardia(AvD)</strong></font><br><font size='1' color='black'>Status:</font><font color='green' size='1' style='Arial'> On</font>$upmessage2"; }

$serverg2 = "xxx.xxx.xx.xxx";
$portg2 = "0000";

function pingDomain3($serverg2){
    $starttime3 = microtime(true);
    $file3      = fsockopen ($domain3, $portg2, $errno, $errstr, 10);
    $stoptime3  = microtime(true);
    $status3    = 0;

    if (!$fi1e3) $status3 = -1;
    else {
        fclose($file3);
        $status3 = ($stoptime3 - $starttime3) * 1000;
        $status3 = floor($status3);
    }
}      

        $status3 = pingDomain3($serverbase3);
        if ($status3 <= 50) $MessageStatus3 = "Great";
        elseif ($status3 <= 80) $MessageStatus3 = "G1ood";
        elseif ($status3 <= 100) $MessageStatus3 = "Ok";
        elseif ($status3 <= 150) $MessageStatus3 = "Bad";
        elseif ($status3 <= 999) $MessageStatus3 = "Poor";
        else $MessageStatus3 = "Disconnected";


$upmessage3 = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>$MessageStatus2</font><br>";
$downmessage3 = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>Disconnected</font><br>";
$tout = "5";
$serverg2 = @fsockopen ($serverg2, $portg2, $errno, $errstr, $tout);
if(!$serverg2){ echo"<br><font color='C8B560' size='2' style='Arial'><strong>Elcardia(PvP)</strong></font><br><font size='1' color='black'>Status:</font><font color='red' size='1' style='Arial'> Off</font>$downmessage3"; }
else { echo"<br><font color='C8B560' size='2' style='Arial'><strong>Elcardia(PvP)</strong></font><br><font size='1' color='black'>Status:</font><font color='green' size='1' style='Arial'> On</font>$upmessage3"; }

?>
Paskutinį kartą temą redagavo Edmundas (2010-02-18 21:20:11), redaguota kartų: 2
 


Atsakymai į temą

Edmundas
Tinklalapio šeimininkas

 
Ne ten temą paskelbei, perkeliu.

Tu IP ir port nurodai?

$server = "xxx.xxx.xx.xxx"; 
$portl = "0000"; 

Čia šiaip uždėjai iksus, ar taip ir palieki skripte? Kintamajam $server turi nurodyti serverio IP adresą, prie kurio nori jungtis. Port'as dažniausiai yra 80, todėl tikiuosi, kad tu ten nulių kintamajame nepalieki.
bontavi
Naujokas

 
pakeiciu

cia pradeda mest kai fsockopen vietoj portl yrasau porta.

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/online.php on line 8

Warning: fsockopen() [function.fsockopen]: unable to connect to :2106 (Unknown error) in /var/www/online.php on line 8
Pask. redagavo bontavi (2010-02-18 20:37:11), redaguota kartų: 1

Edmundas
Tinklalapio šeimininkas

 
Na tai parodyk, ką ten įrašai. Galbū ką nors neteisingai nurodai.
bontavi
Naujokas

 
cia pilnas scriptas su ip ir portais:

<?php

$serverl = "212.122.86.243";
$portl = "2106";

function pingDomain($serverl){
    $starttime = microtime(true);
    $file      = fsockopen ($domain, $portl, $errno, $errstr, 10);
    $stoptime  = microtime(true);
    $status    = 0;

    if (!$file) $status = -1;
    else {
        fclose($file);
        $status = ($stoptime - $starttime) * 12000;
        $status = floor($status);
    }
    return $status;
}      

        $status = pingDomain($serverbase);
        if ($status <= 50) $MessageStatus = "Great";
        elseif ($status <= 80) $MessageStatus = "Good";
        elseif ($status <= 100) $MessageStatus = "Ok";
        elseif ($status <= 150) $MessageStatus = "Bad";
        elseif ($status <= 999) $MessageStatus = "Poor";
        else $MessageStatus = "Disconnected";


$upmessage = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>$MessageStatus</font><br>";
$downmessage = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>Disconnected</font><br>";
$tout = "5";
$server1 = @fsockopen ($serverl, $portl, $errno, $errstr, $tout);
if(!$server1){ echo"<br><font color='C8B560' size='2' style='Arial'><strong>Login</strong></font><br><font size='1' color='black'>Status:</font><font color='red' size='1' style='Arial'> Off</font>$downmessage"; }
else { echo"<br><font color='C8B560' size='2' style='Arial'><strong>Login</strong></font><br><font size='1' color='black'>Status:</font><font color='green' size='1' style='Arial'> On</font>$upmessage"; }

$serverg1 = "212.122.86.243";
$portg1 = "6667";

function pingDomain2($serverg1){
    $starttime2 = microtime(true);
    $file2      = fsockopen ($domain2, $portg1, $errno, $errstr, 10);
    $stoptime2  = microtime(true);
    $status2    = 0;

    if (!$fi1e2) $status2 = -1;
    else {
        fclose($file2);
        $status2 = ($stoptime2 - $starttime2) * 1000;
        $status2 = floor($status2);
    }
}      

        $status2 = pingDomain2($serverbase2);
        if ($status2 <= 50) $MessageStatus2 = "Great";
        elseif ($status2 <= 80) $MessageStatus2 = "G1ood";
        elseif ($status2 <= 100) $MessageStatus2 = "Ok";
        elseif ($status2 <= 150) $MessageStatus2 = "Bad";
        elseif ($status2 <= 999) $MessageStatus2 = "Poor";
        else $MessageStatus2 = "Disconnected";


$upmessage2 = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>$MessageStatus2</font><br>";
$downmessage2 = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>Disconnected</font><br>";
$tout = "5";
$serverg1 = @fsockopen ($serverg1, $portg1, $errno, $errstr, $tout);
if(!$serverg1){ echo"<br><font color='C8B560' size='2' style='Arial'><strong>Elcardia(AvD)</strong></font><br><font size='1' color='black'>Status:</font><font color='red' size='1' style='Arial'> Off</font>$downmessage2"; }
else { echo"<br><font color='C8B560' size='2' style='Arial'><strong>Elcardia(AvD)</strong></font><br><font size='1' color='black'>Status:</font><font color='green' size='1' style='Arial'> On</font>$upmessage2"; }

$serverg2 = "212.122.86.243";
$portg2 = "6666";

function pingDomain3($serverg2){
    $starttime3 = microtime(true);
    $file3      = fsockopen ($domain3, $portg2, $errno, $errstr, 10);
    $stoptime3  = microtime(true);
    $status3    = 0;

    if (!$fi1e3) $status3 = -1;
    else {
        fclose($file3);
        $status3 = ($stoptime3 - $starttime3) * 1000;
        $status3 = floor($status3);
    }
}      

        $status3 = pingDomain3($serverbase3);
        if ($status3 <= 50) $MessageStatus3 = "Great";
        elseif ($status3 <= 80) $MessageStatus3 = "G1ood";
        elseif ($status3 <= 100) $MessageStatus3 = "Ok";
        elseif ($status3 <= 150) $MessageStatus3 = "Bad";
        elseif ($status3 <= 999) $MessageStatus3 = "Poor";
        else $MessageStatus3 = "Disconnected";


$upmessage3 = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>$MessageStatus2</font><br>";
$downmessage3 = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>Disconnected</font><br>";
$tout = "5";
$serverg2 = @fsockopen ($serverg2, $portg2, $errno, $errstr, $tout);
if(!$serverg2){ echo"<br><font color='C8B560' size='2' style='Arial'><strong>Elcardia(PvP)</strong></font><br><font size='1' color='black'>Status:</font><font color='red' size='1' style='Arial'> Off</font>$downmessage3"; }
else { echo"<br><font color='C8B560' size='2' style='Arial'><strong>Elcardia(PvP)</strong></font><br><font size='1' color='black'>Status:</font><font color='green' size='1' style='Arial'> On</font>$upmessage3"; }

?>
Pask. redagavo bontavi (2010-02-18 20:39:58), redaguota kartų: 1

Edmundas
Tinklalapio šeimininkas

 
Pas tave šiek tiek nepraktiškai viskas padaryta, kartojasi tas pats kodas, kas yra nevisai gerai. Kitaip sakant, bereikalingos funkcijs pingDomain2 ir pingDomain3. Tai galima atlikti su viena funkcija.

function pingDomain($server, &$port)
{
    $start_time         = microtime(true); 
    $file               = @fsockopen ($server, $port, $errno, $errstr, 10); 
    $stop_time          = microtime(true); 
    $status    	        = 0; 
    
    if(!$file)
    {
    	 $status = -1; 
    } 
    else 
    { 
        fclose($file); 
        $status = ($stop_time - $start_time) * 12000; 
        $status = floor($status); 
    } 
    
    return $status; 
}


Taip pat galima sukurti dar vieną funkciją, kuri išvestų serverio statusą (pagal ping).

function server_status($ping = 0)
{
	if($ping <= 50) 
	{
		$MessageStatus = 'Great';
	}
	elseif($ping <= 80)
	{
		$MessageStatus = 'Good';
	}
	elseif($ping <= 100)
	{
		$MessageStatus = 'OK';
	}
	elseif($ping <= 150)
	{
		$MessageStatus = 'Bad';
	}
	elseif($ping <= 999)
	{
		$MessageStatus = 'Poor';
	}
	else
	{
		$MessageStatus = 'Disconnected';
	}
	
	return $MessageStatus;
}


Taigi vėliau nurodai visus reikiamus serverius ir jų portus vienoje vietoje.

$server_1 	= 	'212.122.86.243';
$port_1		= 	'2106';

$server_2	=	'212.122.86.243';
$port_2		=	'6667';

$server_3	=	'212.122.86.243';
$port_3		=	'6666';


Galiausiai išbandome, kaip viskas veikia.

$status = pingDomain($server_1, $port_1); 
	
$MessageStatus = server_status($status);
	

$upmessage = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>$MessageStatus</font><br>"; 
$downmessage = "<font size='1' color='black'><br>Stability: </font><font color='gray' size='1'>Disconnected</font><br>"; 
$tout = "5"; 
$serverg1 = @fsockopen ($server_1, $port_1, $errno, $errstr, $tout); 
if(!$serverg1)
{ 
	echo "<br>
		<font color='C8B560' size='2' style='Arial'><strong>Login</strong></font>
		<br>
		<font size='1' color='black'>Status:</font>
		<font color='red' size='1' style='Arial'> Off</font>$downmessage"; 
} 
else 
{ 
	echo"<br>
		<font color='C8B560' size='2' style='Arial'><strong>Login</strong></font>
		<br>
		<font size='1' color='black'>Status:</font>
		<font color='green' size='1' style='Arial'> On</font>$upmessage"; 
}


Įdėjau visą kodą į pastie.org. Patikrinau, lyg ir viskas veikia be klaidų.
bontavi
Naujokas

 
dekingas uz pagalba