How to check connection in PHP?

Suppose you are now connected to a jabber server,

then how can you check if the connection to the jabber server is lost?

+3
source share
2 answers

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

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

I'm not quite sure how Jabber works compared to any other protocol, but I believe that you will need to make a socket connection to the server, for example:

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

while() , PHP script. , while(), , while(), .

+1

Source: https://habr.com/ru/post/1709638/


All Articles