tags:

views:

81

answers:

2

Suppose you are now connected to a jabber server,

then how can you check whether your connection to the jabber server is lost or not?

+1  A: 

I'm not entirely sure about how Jabber works compared to any other protocol, but I believe that you would need to make a socket connection to the server, something like:

$endpoint = "SERVER";
$fp = fopen( $endpoint, "r" ) or die();
while ( ! feof( $fp )){
    // Heavy duty work goes here.
    print fgets( $fp, 1024 );
}

That while() loop will run until the socket connection stops returning data to the PHP script. Therefore, so long as your logic is within one such while() loop, the only time it should leave the while() loop is upon a connection termination.

Jason
+1  A: 

Try fsockopen (http://us3.php.net/fsockopen):

$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
//if the socket failed it's offline...
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
}
christo16