From:             kvr at centrum dot cz
Operating system: Linux, Debian
PHP version:      5.3SVN-2009-11-27 (snap)
PHP Bug Type:     HTTP related
Bug description:  Opening an https using fopen consumes all cpu time

Description:
------------
When connecting to https server using fopen("https://...";), php
consumes all cpu time until the connection is established. When there
is problem with the remote https server, the cpu is occupied until
the script runs out of time.

Full version information: PHP 5.3.0-0.dotdeb.8 with Suhosin-Patch
0.9.7 (cli) (built: Aug 12 2009 18:11:27)


Reproduce code:
---------------
The following code can be used to reproduce:
$fd = fopen("https://whatever.com/index.html";, "r")


Expected result:
----------------
The code should open the connection without busy waits.

Actual result:
--------------
The code keeps trying reading on non-blocked socket until some data
is received, see the strace:
25832 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 38
25832 fcntl64(38, F_GETFL)              = 0x2 (flags O_RDWR)
25832 fcntl64(38, F_SETFL, O_RDWR|O_NONBLOCK) = 0
25832 connect(38, {sa_family=AF_INET, sin_port=htons(443),
sin_addr=inet_addr("w.x.y.z")}, 16) = -1 EINPROGRESS (Operation now
 in progress)
25832 poll([{fd=38, events=POLLIN|POLLOUT|POLLERR|POLLHUP}], 1, 60000
<unfinished ...>
25832 <... poll resumed> )              = 1 ([{fd=38,
revents=POLLOUT}])
25832 getsockopt(38, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
25832 fcntl64(38, F_SETFL, O_RDWR)      = 0
25832 fcntl64(38, F_GETFL)              = 0x2 (flags O_RDWR)
25832 fcntl64(38, F_SETFL, O_RDWR|O_NONBLOCK) = 0
25832 gettimeofday({1259327624, 794801}, {4294967176, 0}) = 0
25832 time(NULL)                        = 1259327624
25832 time(NULL)                        = 1259327624
25832 write(38,
"\200d\1\3\1\0K\0\0\0\20\0\0009\0\0008\0\0005\0\0\26\0\0\23\0\0\n\7\0
0\200\0\0\25\0\0\22\0\0\t\...@\0\0\24\0\0\21\0\0\10\0\0\6\4\0\200\0\0
25832 read(38, 0x8e62f78, 7)            = -1 EAGAIN (Resource
temporarily unavailable)
25832 gettimeofday({1259327624, 795389}, {4294967176, 0}) = 0
25832 gettimeofday({1259327624, 795463}, {4294967176, 0}) = 0
25832 time(NULL)                        = 1259327624
25832 read(38, 0x8e62f78, 7)            = -1 EAGAIN (Resource
temporarily unavailable)
... read repeats many times / or forever instead of polling socket
for POLLIN.
25832 read(38, 0x8e62f78, 5)            = -1 EAGAIN (Resource
temporarily unavailable)
25832 gettimeofday({1259327624, 893179}, {4294967176, 0}) = 0
25832 gettimeofday({1259327624, 893222}, {4294967176, 0}) = 0
25832 time(NULL)                        = 1259327624
25832 read(38, "\24\3\1\0\1", 5)        = 5
When / if the data is received, the communication continues
correctly.

-- 
Edit bug report at http://bugs.php.net/?id=50312&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50312&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50312&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50312&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50312&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50312&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50312&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50312&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50312&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50312&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50312&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50312&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50312&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50312&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50312&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50312&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50312&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50312&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50312&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50312&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50312&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50312&r=mysqlcfg

Reply via email to