From: joel dot washburn at gmail dot com Operating system: Windows (Any) PHP version: 5.1.2 PHP Bug Type: Sockets related Bug description: fread using 99% CPU in Windows with SSL Connection
Description: ------------ php.exe uses 99% CPU while polling SSL sockets for data. I can reproduce this issue in IIS and Apache using php5isapi.dll and php5apache2.dll. This is a nightmare for php scripts using third party API calls via SSL sockets. If the API call takes a few seconds to run, the CPU is maxed out waiting on a response. This is not an issue on linux systems. This is not an issue on Windows using clean sockets (only SSL). Reproduce code: --------------- Below is a simple way to reproduce the problem with fgets(): Create two files, one (timer.php) has to be accessable from the web (HTTP and HTTPS) and the other can be ran from the command prompt (pingtimer.php). When you run pingtimer.php using SSL, php.exe will stick at 99% CPU in Task Manager. When you run it using clean sockets, its idle while waiting for a response. timer.php : <?php sleep(10); print "<html><body>10 sec. are up!</body></html>"; ?> pingtimer.php: <?php //$sock = fsockopen("localhost", 80); $sock = fsockopen("ssl://localhost", 443); $query = "GET /timer.php HTTP/1.1\r\n"; $query .= "Host: localhost\r\n"; $query .= "Connection: Close\r\n\r\n"; fwrite($sock, $query); while (!feof($sock)) { echo fgets($sock, 128); } fclose($sock); ?> Expected result: ---------------- CPU usage should be very little or zero while waiting for a response. Actual result: -------------- 99% CPU usage in Windows Task Manager from php.exe while waiting on a response. -- Edit bug report at http://bugs.php.net/?id=36479&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36479&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36479&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36479&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36479&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36479&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36479&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36479&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36479&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36479&r=support Expected behavior: http://bugs.php.net/fix.php?id=36479&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36479&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36479&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36479&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36479&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36479&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36479&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36479&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36479&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36479&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36479&r=mysqlcfg