[PHP] UDP problem
#1

Hello!

I have a little PHP question.
I am trying to retrieve data from my server. Everything is working fine when server is online, but when the server is offline, the page continues to load 60 seconds longer and doesn't even display the "OFFLINE" message.

Код:
$fp = fsockopen('udp://' . $ip, $port, $errno, $errstr,0.0);
if (!$fp)
{
     echo 'Server is offline.';
}
else
{
...
}
I've read on the PHP website that udp don't have a real 'connection' and if the host is unreachable it won't return a error (FALSE @ $fp). Though it said it will return at fwrite or fread. But the problem is that it never leaves fsockopen function.

Do you have any ideas how to fix this? Maybe a connection checker before opening a socket.
I'm very curious how this (http://typefish.co.uk/samp-conn/) is working, it's fast and doesn't hang if host is unreachable.

Thanks.
Reply
#2

fsockopen ($hostname, $port, &$errno, &$errstr, $timeout)

Код:
$fp = fsockopen('udp://' . $ip, $port, $errno, $errstr, 1.0);
Reply
#3

typefish probably uses a modified version of this class, seeing as the person who wrote the class also owns that website.

Take a look at the class for more information on fsockopen() in PHP and how it's used to query a SA-MP server.
Reply
#4

Quote:
Originally Posted by Isset
Посмотреть сообщение
fsockopen ($hostname, $port, &$errno, &$errstr, $timeout)

Код:
$fp = fsockopen('udp://' . $ip, $port, $errno, $errstr, 1.0);
I've used a series of timeout values and it's simply ignoring it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)