Forum Moderators: coopster

Message Too Old, No Replies

fsockopen format

         

lindajames

10:08 pm on Jul 13, 2003 (gmt 0)

10+ Year Member



i have the following fsockopen tag in my script,

$fp = fsockopen($ip,$port,$errno,$errstr,10);

i know what $ip is and $port and 10 but i dont know what $errno & $errstr is, any idea?

Cheers
Linda

hakre

10:15 pm on Jul 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi linda ;),

if the connection fails ($fp = false), $errno & $errstr will contain error information. you can do an output in case of an error:


if ($fp)
{
echo("<img src='image1.gif'>");
fclose($fp);
}
else
{
echo("<img src='image2.gif'>");
echo("<p><b>Error #$errno:</b> $errstr</p>");
}

- hakre

lindajames

10:22 pm on Jul 13, 2003 (gmt 0)

10+ Year Member



thanx alot for your help hakre, really appreciated

lindajames

12:24 pm on Jul 14, 2003 (gmt 0)

10+ Year Member



if fsockopen() is unable to connect to a certain ip:port within the time-out period, i get the following error messages:

Warning: fsockopen(): php_hostconnect: connect failed
Warning: fsockopen(): unable to connect

Can anyone tell me if there is anyway to actually disable those messages from being displayed?

Cheers
Linda

Knowles

1:31 pm on Jul 14, 2003 (gmt 0)

10+ Year Member



Just add an @ sign in front of fsockopen.

$fp = @fsockopen($ip,$port,$errno,$errstr,10);

lindajames

6:28 pm on Jul 14, 2003 (gmt 0)

10+ Year Member



i've currently got the following code:

if ($fp)
{
header( "Location: alive.html" );
fclose($fp);
}

but im assuming this is not correct as the code probably cannot execute the line that says: fclose($fp); because of the fact that its being redirected somewhere else before it can get to that line of command. Is this so? if so can anyone please tell me the correct format it should be in?

Cheers
Linda

Knowles

7:50 pm on Jul 14, 2003 (gmt 0)

10+ Year Member



This should work... you dont really need the socket once you already know its true. So close it then transfer them to the other page.

if ($fp)
{
fclose($fp);
header( "Location: alive.html" );
}

Timotheos

9:12 pm on Jul 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Linda,

The code after header("Location: alive.html") will execute so either way it should be no problem. If you do not want to execute the code afterwards then you'd need something like this.

header("Location: alive.html");
exit;

See ya,
Tim