note 23668 modified in function.socket-connect by danbrown

From: Date: Thu, 18 Nov 2010 23:36:22 +0000
Subject: note 23668 modified in function.socket-connect by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174165@lists.php.net to get a copy of this message
I had the same problem with the timeout, and i applied this solution. It works only on linux PHP, i make a ping to the ip before connect the socket..... <?php $address = gethostbyname ($ip); $command = "ping -c 1 " . $address; $r = exec($command); if ($r[0]=="r") { $socket = socket_create (AF_INET, SOCK_STREAM, 0); if ($socket < 0) { echo "socket_create() failed: reason: " . socket_strerror ($socket) . "\n"; } else { echo "OK.\n"; } ?> --was-- I had the same problem with the timeout, and i applied this solution. It works only on linux PHP, i make a ping to the ip before connect the socket..... $address = gethostbyname ($ip); $command = "ping -c 1 " . $address; $r = exec($command); if ($r[0]=="r") { $socket = socket_create (AF_INET, SOCK_STREAM, 0); if ($socket < 0) { echo "socket_create() failed: reason: " . socket_strerror ($socket) . "\n"; } else { echo "OK.\n"; } http://php.net/manual/en/function.socket-connect.php

« previous php.notes (#174165) next »