Bug #69428 [Com]: fgets blocks and consumes CPU on a non-blocking TLS stream without data
Edit report at https://bugs.php.net/bug.php?id=69428&edit=1
ID: 69428
Comment by: nathan dot renniewaldock at gmail dot com
Reported by: nathan dot renniewaldock at gmail dot com
Summary: fgets blocks and consumes CPU on a non-blocking TLS
stream without data
Status: Duplicate
Type: Bug
Package: OpenSSL related
Operating System: Ubuntu 12.04
PHP Version: 5.6.7
Block user comment: N
Private report: N
New Comment:
Must've missed that one when searching. But that one is correct, my blank lines are from it
returning after timeout is exceeded.
Previous Comments:
------------------------------------------------------------------------
[2015-04-11 23:03:36] requinix@php.net
Related To: Bug #69402
------------------------------------------------------------------------
[2015-04-11 23:02:25] requinix@php.net
Duplicate of bug #69402
------------------------------------------------------------------------
[2015-04-11 22:56:27] nathan dot renniewaldock at gmail dot com
Description:
------------
TLS streams are blocking and consuming 100% CPU when there's no data when set to non-blocking.
Test script is using a local IRC server so I didn't have to write a server. Removing tls:// and
changing the port to 6667 works as expected.
Test script:
---------------
<?php
$context = stream_context_create();
stream_context_set_option($context, "ssl", "verify_peer", false);
$fp = stream_socket_client("tls://localhost:6697", $errno, $errstr, 10,
STREAM_CLIENT_CONNECT, $context) or die();
stream_set_blocking($fp, 0);
while (!feof($fp)) {
echo microtime(true)." Reading...\n";
$line = fgets($fp);
echo microtime(true)." $line\n";
if (!$fp) {
usleep(10000);
}
}
@fclose($fp);
?>
Expected result:
----------------
"Reading..." should repeat every ~10ms and CPU usage should be low
Actual result:
--------------
$ php test.php
1428791498.132599 Reading...
1428791498.171197 :localhost NOTICE AUTH :*** Looking up your hostname...
1428791498.171224 Reading...
1428791498.171237 :localhost NOTICE AUTH :*** Found your hostname (cached)
1428791498.171251 Reading...
# At this point htop shows it using 100% CPU until the server send a blank line to check the
connection hasn't broken
1428791508.17128
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69428&edit=1
Thread (5 messages)