Bug #69428 [Opn->Dup]: fgets blocks and consumes CPU on a non-blocking TLS stream without data

From: Date: Sat, 11 Apr 2015 23:02:25 +0000
Subject: Bug #69428 [Opn->Dup]: fgets blocks and consumes CPU on a non-blocking TLS stream without data
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191983@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69428&edit=1 ID: 69428 Updated by: requinix@php.net Reported by: nathan dot renniewaldock at gmail dot com Summary: fgets blocks and consumes CPU on a non-blocking TLS stream without data -Status: Open +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: Duplicate of bug #69402 Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#191983) next »