Socket_connect() timeout
| From: | Max Clark | Date: | Sun, 15 Dec 2002 18:26:50 +0000 |
| Subject: | Socket_connect() timeout | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-128339@lists.php.net to get a copy of this message | ||
Warning: socket_connect() unable to connect [60]: Operation timed out in
/usr/home/maxc/public_html/admin/functions.inc on line 66
Is there any way to time out this function? I only want to wait 5 seconds.
Thanks in advance,
Max
"Johannes Schlueter" <php@schlueters.de> wrote in message
news:200212132141.56561.php@schlueters.de...
On Friday 13 December 2002 21:30, Max Clark wrote:
> I found the socket_create function that is listed as experimental and
> requires a re-compile of php. Is there a built in way to perform this kind
> of test?
Based upon the second example on
http://www.php.net/manual/en/ref.sockets.php
:
echo "<h2>TCP/IP Connection</h2>\n";
/* Get the service for TCP-Port 25. */
$service_port = getservbyport (25, 'tcp');
/* Get the IP address for the target host. */
$address = gethostbyname ('www.example.com');
/* Create a TCP/IP socket. */
$socket = socket_create (AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
echo "socket_create() failed: reason: " . socket_strerror ($socket) .
"\n";
} else {
echo "OK.\n";
}
echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect ($socket, $address, $service_port);
if ($result < 0) {
echo "socket_connect() failed.\nReason: ($result) " .
socket_strerror($result) . "\n";
} else {
echo "OK.\n";
}
johannes
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php