php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62605 stream_set_timeout does not affect on sll socket connections
Submitted: 2012-07-19 05:43 UTC Modified: 2021-10-10 04:22 UTC
Votes:23
Avg. Score:4.8 ± 0.6
Reproduced:21 of 21 (100.0%)
Same Version:7 (33.3%)
Same OS:5 (23.8%)
From: sempasha at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: Network related
PHP Version: 5.3.14 OS: Windows 7, CentOS 6.3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sempasha at gmail dot com
New email:
PHP Version: OS:

 

 [2012-07-19 05:43 UTC] sempasha at gmail dot com
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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-12 12:09 UTC] bbroerman at bbroerman dot net
My company despirately needs this to be fixed! We are experiencing the same issue ( from within a PHP extension we are developing ). We really need this to be able to support SSL with read timeouts!
 [2021-10-01 11:35 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-10-01 11:35 UTC] cmb@php.net
With PHP-7.4 on Windows, I get:

> 3. stream_set_timeout works fine and reading breaked by timeout
> >test.php
> Stream is timed out at line 21 in file test.php

Can anybody else still reproduce this issue with any of the
actively supported PHP versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2021-10-10 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 19:01:28 2024 UTC