|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-11-27 13:37 UTC] kvr at centrum dot cz
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\6\0@\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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 04:00:01 2025 UTC |
Unless of course your provided "code" is supposed to work at all? This works too: # php -r '$fd = fopen("https://master.php.net/manage/users.php", "r");'This doesn't happen anymore. As we can see from the strace, we now sit in poll() until the timeout at 60s: 29667 1422765514.330841 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 <0.000027> 29667 1422765514.330914 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR) <0.000014> 29667 1422765514.330967 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0 <0.000015> 29667 1422765514.331025 connect(3, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr("123.125.114.144")}, 16) = -1 EINPROGRESS (Operation now in progress) <0.000050> 29667 1422765514.331138 poll([{fd=3, events=POLLIN|POLLOUT|POLLERR|POLLHUP}], 1, 60000) = 0 (Timeout) <60.060063> 29667 1422765574.391342 fcntl(3, F_SETFL, O_RDWR) = 0 <0.000049> 29667 1422765574.391565 close(3) = 0 <0.000076>