From: sempasha at gmail dot com
Operating system: Windows 7, CentOS 6.3
PHP version: 5.3.14
Package: Network related
Bug Type: Bug
Bug description:stream_set_timeout does not affect on sll socket connections
Description:
------------
Unable to set read timeout for socket which work with SSL connection by
stream_set_timeout function. In other case, when we use socket with non-SSL
connection, socket_set_timeout works fine. There are 2 potential problems:
1. stream_set_timeout returns TRUE, but does not works as expected
2. stream_set_timeout does not work for sockets with SSL connections
Related bugs are #23618, #35105, #43796, #47929.
Some patches attached to every related bug, but still not fixed in PHP.
It's hard to believe, that since year 2003 nothing was done on this
problem.
Test script:
---------------
<?php
// test.php
// on port 8000 at 127.0.0.1 runs daemon, which accepts incoming
connections and nothing more
$socket = fsockopen('ssl://127.0.0.1', 8000, $errno, $errstr, 10);
if (!is_resource($socket))
die('Socket connection error '.$errno.', '.$errstr.' at line
'.__LINE__.'
in file '.__FILE__);
if (!stream_set_timeout($socket, 1))
die('Unable to set stream timeout at line '.__LINE__.' ion file
'.__FILE__);
if (!set_time_limit(2))
die('Unable to set time limit at line '.__LINE__.' ion file '.__FILE__);
$message = fread($socket, 1024).PHP_EOL;
$metadata = stream_get_meta_data($socket);
if ($metadata['timed_out'])
die('Stream is timed out at line '.__LINE__.' in file '.__FILE__);
Expected result:
----------------
Possible output variants:
1. socket open error
>test.php
Socket connection error SOCKET-OPEN-ERROR-CODE, SOCKET-OPEN-ERROR-TEXT at
line 8 in file test.php
2. stream_set_timeout error
>test.php
Unable to set stream timeout at line 11 ion file test.php
3. stream_set_timeout works fine and reading breaked by timeout
>test.php
Stream is timed out at line 21 in file test.php
4. stream_set_timeout does not affect (despite the fact it returns TRUE)
and limit of script execution time exceeded
>test.php
Fatal error: Maximum execution time of 2 seconds exceeded in test.php on
line 16
Actual result:
--------------
Real output variants:
1. socket open error
>test.php
Socket connection error SOCKET-OPEN-ERROR-CODE, SOCKET-OPEN-ERROR-TEXT at
line 8 in file test.php
2. stream_set_timeout never return FALSE
>test.php
Unable to set stream timeout at line 11 ion file test.php
3. stream_set_timeout does not affect, reading never ends, empty output
>test.php
4. stream_set_timeout does not affect (despite the fact it returns TRUE)
but limit of script execution time will never reached, empty output,
reading never ends
>test.php
--
Edit bug report at https://bugs.php.net/bug.php?id=62605&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=62605&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=62605&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=62605&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=62605&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=62605&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=62605&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=62605&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=62605&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=62605&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=62605&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=62605&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=62605&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=62605&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=62605&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=62605&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62605&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=62605&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=62605&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=62605&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=62605&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=62605&r=mysqlcfg