|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53592 stream_socket_enable_crypto() uses NONBLOCK
Submitted: 2010-12-22 04:06 UTC Modified: 2010-12-23 02:45 UTC
From: jerry dot wilborn at paetec dot com Assigned: cataphract (profile)
Status: Closed Package: Sockets related
PHP Version: 5.3.4 OS: CentOS 4.4
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: jerry dot wilborn at paetec dot com
New email:
PHP Version: OS:


 [2010-12-22 04:06 UTC] jerry dot wilborn at paetec dot com
stream_socket_enable_crypto() changes the stream to NONBLOCK before it attempts 
the encryption.  I'm assuming this is so the timeout can be tracked, but for 
connections where the handshake doesn't work the process simply chews up CPU while 
the read() repeatedly EAGAIN fails and gettimeofday() is called.

Test script:
$stream = stream_socket_client("tcp://", $errno, $errstr, 5);
stream_socket_enable_crypto($stream, TRUE, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);

Expected result:
For the socket to stay in blocked mode.

Actual result:
fcntl64(3, F_GETFL)                     = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
connect(3, {sa_family=AF_INET, sin_port=htons(80), 
sin_addr=inet_addr("")}, 16) = -1 EINPROGRESS (Operation now in 
poll([{fd=3, events=POLLIN|POLLOUT|POLLERR|POLLHUP, revents=POLLOUT}], 1, 1000) = 
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
fcntl64(3, F_SETFL, O_RDWR)             = 0
select(4, [3], [3], [], {5, 0})         = 1 (out [3], left {5, 0})
fcntl64(3, F_GETFL)                     = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK)  = 0


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-22 14:59 UTC] jerry dot wilborn at paetec dot com
-Summary: stream_socket_client uses NONBLOCK +Summary: stream_socket_enable_crypto() uses NONBLOCK
 [2010-12-22 14:59 UTC] jerry dot wilborn at paetec dot com
Fix summary.
 [2010-12-22 16:21 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: cataphract
 [2010-12-22 16:43 UTC]
This doesn't seem a problem only where the handshake doesn't work. Testing with a host with 10 ms latency, I count:

* More than 11k read() calls if enabling SSL succeeds (probably because more messages are exchanged)
* Only 900 read() calls if enabling SSL doesn't succeed
 [2010-12-22 17:47 UTC]
This bug was introduced when fixing bug #39571.
 [2010-12-23 02:44 UTC]
Automatic comment from SVN on behalf of cataphract
Log: - Fixed bug #53592 (stream_socket_enable_crypto() busy-waits in client mode).
- Fixed stream_socket_enable_crypto() not honoring the socket timeout in
  server mode.
 [2010-12-23 02:45 UTC]
-Status: Assigned +Status: Closed
 [2010-12-23 02:45 UTC]
This bug has been fixed in SVN.

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.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Oct 03 20:01:25 2023 UTC