#39571 [NEW]: fsockopen timeout param does not affect ssl/tls handshake
| From: | tim at tmcode dot com | Date: | Tue, 21 Nov 2006 16:23:54 +0000 |
| Subject: | #39571 [NEW]: fsockopen timeout param does not affect ssl/tls handshake | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-105258@lists.php.net to get a copy of this message | ||
From: tim at tmcode dot com
Operating system: Linux
PHP version: 5CVS-2006-11-21 (CVS)
PHP Bug Type: Sockets related
Bug description: fsockopen timeout param does not affect ssl/tls handshake
Description:
------------
The 5th parameter of the fsockopen function does not appear to account for
a webserver taking too long to complete the ssl/tls handshake. When
connecting to an extremely loaded server, the connection might establish
within the timeout but the ssl handshake could take much longer. From
what I can tell there is no way to set the read/write timeout prior to
running fsockopen, making it impossible to prevent PHP from hanging on a
slow ssl server?
(I tried to find a similar bug or a mention of this issue in the manual so
I appologize if I need to go RTFM more carefully).
This problem only affects fsockopen if you use ssl:// or tls:// in the
first param. If you modifiy the code below and just remove the ssl://
the function call works fine.
Reproduce code:
---------------
// client code:
$fp = fsockopen("ssl://$server", 443, $errno, $errstr, 5);
If you want to simulate a "hung" ssl server to verify that the timeout
does not happen in 5 seconds:
// server code:
$sock=socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
if(!socket_bind($sock,$serverip,443)) die("bind\n");
if(!socket_listen($sock,25)) die("listen\n");
if(!socket_set_nonblock($sock)) die("nonblock\n");
while(1)
{
$newfd=@socket_accept($sock);
sleep(30);
}
Expected result:
----------------
fsockopen should timeout after 5 seconds.
Actual result:
--------------
fsockopen times out after 58 seconds (with the test server code above).
Change sleep to something larger and the timeout will take even longer.
--
Edit bug report at http://bugs.php.net/?id=39571&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39571&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39571&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39571&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39571&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=39571&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39571&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39571&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39571&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39571&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39571&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=39571&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=39571&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39571&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39571&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39571&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39571&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39571&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39571&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39571&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39571&r=mysqlcfg