|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35105 stream_set_timeout() has no effect on SSL stream
Submitted: 2005-11-04 15:07 UTC Modified: 2006-12-30 02:35 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: wckits at rit dot edu Assigned: wez (profile)
Status: Closed Package: Streams related
PHP Version: 5CVS-2005-11-08 (snap) OS: SunOS 5.9
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
37 - 13 = ?
Subscribe to this entry?

 [2005-11-04 15:07 UTC] wckits at rit dot edu
A stream opened with stream_socket_client("ssl://..... will not timeout when reading.

This may have a similar underlying cause to bug #23618 but it is exposed differently, and is still a problem in 5.0.5.

Reproduce code:
//First connect and do something to prove that we are properly connected.

print "Setting up context\n";
$ctx = stream_context_create(array(
                                'verify_peer' => false,
                                'allow_self_signed' => true,
print "Creating socket\n";
$socket = stream_socket_client( "ssl://", &$errno, &$errstr, 10, STREAM_CLIENT_CONNECT, $ctx );
print "Setting timeout\n";
var_dump(stream_set_timeout( $socket, 5 ));
print "Sending bogus request\n";
fwrite($socket, "GET nourl Cupcakes/2.5\n\n\n\n" );
print "Reading Result\n";
var_dump(fgets( $socket));

//Now conenct and read when we know the server isnt going to send anything

print "Creating NEW socket\n";
$socket = stream_socket_client( "ssl://", &$errno, &$errstr, 10, STREAM_CLIENT_CONNECT, $ctx );
print "Setting timeout\n";
var_dump(stream_set_timeout( $socket, 5 ));
print "Sending NO request\n";
print "Read should time out in 5....\n";
var_dump(fgets( $socket));

Expected result:
The first section will run and print an HTTP error. The second section will run and timeout after printing "Read should timeout in 5..."

Actual result:
Read does not time out.

I suspect that the read timeout on SSL connections is just not implemented, because it is hard, but if that is the case the stream_set_timeout should return false to indicate the error.

If its just not implemented I'd be willing to patch it up if there is one place to fix it. If there are ssl reads all over the php source I don't think I'd have the time to track them all down.

I have seen people say "just use select" in response to stream timeout problems. That does not work with ssl, or at least it may not always work with ssl. Select can be used if you have access to the native SSL interface (ie: it could be done right in C) but you need to be able to check for the WANT_READ condition....


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-08 19:43 UTC] wckits at rit dot edu
'Latest' (php5-200511081330) just wont build on my system, same configuration as 5.0.5... Unless you are willing to cut and paste the example code into your own latest cvs build this may have to wait for the next stable release.
 [2005-11-08 20:14 UTC]
Guess what? The snapshot you tried IS the next stable release.
So can you please tell us what didn't work with it?
Just saying "it wont build" does not help much..

 [2005-11-08 21:07 UTC] wckits at rit dot edu
Ok, I figured it was just the copy in cvs being broken (some feature half done or some such), I wasn't trying to be a jerk. I had to add -mimpure-text to CFLAGS for the last few linking steps to fix the problem (otherwise I'd get about 16,000 lines of linker errors).


> /u01/wckits/php5-200511081730/sapi/cli/php

PHP Version => 5.1.0RC5-dev

System => SunOS myHostname 5.9 Generic_117171-13 sun4u
Build Date => Nov  8 2005 14:52:09

The timeout problem still exists in php5-latest.
 [2005-11-08 21:31 UTC]
Assigned to the maintainer and author of streams.

 [2006-12-30 02:35 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2013-01-19 18:06 UTC] bbroerman at bbroerman dot net
I can still recreate this issue in the current 5.4 branch of PHP.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 11:01:34 2024 UTC