note 56864 added to function.socket-connect
| From: | ScriptBlue at nyc dot rr dot com | Date: | Sat, 17 Sep 2005 16:13:33 +0000 |
| Subject: | note 56864 added to function.socket-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95332@lists.php.net to get a copy of this message | ||
If you do want to have a socket_connect operation timeout you can use the following code.
<?php
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_nonblock($sock);
socket_connect($sock,"127.0.0.1", 80);
socket_set_block($sock);
switch(socket_select($r = array($sock), $w = array($sock), $f = array($sock), 5))
{
case 2:
echo "[-] Connection Refused\n";
break;
case 1:
echo "[+] Connected\n";
break;
case 0:
echo "[-] Timeout\n";
break;
}
?>
This basically makes socket_connect return immediately then you can use socket_select to see how the
socket reacted.
----
Manual Page -- http://www.php.net/manual/en/function.socket-connect.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56864
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56864&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56864&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56864&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56864&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56864&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+56864&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56864&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56864&report=yes
Search -- http://master.php.net/manage/user-notes.php