Bug #80931 [Com]: file_get_contents() hangs with HTTP/1.1 if server doesn't close connection

From: Date: Thu, 10 Aug 2023 16:52:34 +0000
Subject: Bug #80931 [Com]: file_get_contents() hangs with HTTP/1.1 if server doesn't close connection
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245154@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80931&edit=1

 ID:                 80931
 Comment by:         r dot hessel dot git at gmail dot com
 Reported by:        gilperon at gmail dot com
 Summary:            file_get_contents() hangs with HTTP/1.1 if server
                     doesn't close connection
 Status:             Verified
 Type:               Bug
 Package:            Streams related
 Operating System:   any
 PHP Version:        7.4
 Block user comment: N
 Private report:     N

 New Comment:

Same issue, oddly only on Linux. 
Have 2 devs using docker on WSL2 and 1 using Linux Mint, and a UAT environment on Jelastic, all with
the same docker container. 

The windows WSL2 users have no issue, but the linux mint environment does, and so does the Jelastic
UAT.

Tested with these docker containers:
jelastic/nginxphp:1.22.1-php-8.1.14
jelastic/nginxphp:1.24.0-php-8.1.21


Details on the Linux Mint version:
Linux Mint 21.2 (ubuntu 22.04.2 based)
Docker version 24.0.5, build ced0996


Previous Comments:
------------------------------------------------------------------------
[2023-05-25 09:59:10] nguyenthuongzl633 at gmail dot com

The PHP website is every time give us very imp info. all time our work is easy.
(https://www.paybyplatema.one/)github.com

------------------------------------------------------------------------
[2023-01-12 18:06:59] tgross at m-s dot de

I can confirm this problem when using php inside a docker 4.15.0 container.

try these docker commands (In my case, I call them inside WSL2 using Docker Desktop):
This one works well (it returns fast):

> docker run --rm php:7.3 php -d default_socket_timeout=10 -r "file_get_contents('https://github.com/');"

while this one hits the timeout (in this case, 10 seconds) (remove spaces from url!):

> docker run --rm php:7.3 php -d default_socket_timeout=10 -r "file_get_contents('https
> : // www . google . com /');"

It's basically the same with PHP 7.4, 8.1, 8.2. However, with PHP 8.1 and 8.2, the command
reaches twice the timeout - so it takes 20 seconds instead of 10!

Not only file_get_contents() is affected by this problem, but also SoapClient::__construct(), for
example.

------------------------------------------------------------------------
[2023-01-09 15:14:46] dominik+phpnet at komail dot ch

I can confirm the issue of Jamie, that file_get_contents() hangs indefinitely, if it's calling
an URL in the web from a docker container. This started to occur when we updated to the latest
docker version. I'm not sure, in which version exactly, though.

Currently using php8.1 and docker4.15

------------------------------------------------------------------------
[2022-12-13 12:58:07] jamie at hazaar dot io

I have noticed this also ocurring in versions of PHP including 7.1.x and 8.1.x when used from inside
a docker container.  It appears that regardless of the protocol used, Docker will alter the request
headers to use HTTP/1.1 which is particularly problematic when the client has requested HTTP/1.0
with a "Connection: close" header as the server will not see this and as such not close
the connection as requested. 

I now have a bunch of projects that I'm trying to port to Docker containers for development and
deployment that simply do not work because of this bug thanks to both PHP and Docker not playing
nice together.

If anyone reads this and is able to confirm that PHP from inside Docker can not use
file_get_contents($url), please respond here.

------------------------------------------------------------------------
[2022-12-02 08:51:06] arjan at avoid dot org

Seems this (or a very similar) issue is back in PHP8.1.12 and 8.1.13.
Super simple test case:

<?php
print
file_get_contents('https'.'://'.'www'.'nrc'.'nl');

?>

It seems impossible to access the Dutch NRC website (national newspaper).
This takes a very long time to run. It does eventually return.
Accessing the same website from the cmdline via wget or curl is super fast.
I've tested this on multiple PHP instances around the world, they all hang when running on
PHP8.1.12 or 8.1.13. 
This same script ran fine (fast) on PHP 7.4.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=80931


--
Edit this bug report at https://bugs.php.net/bug.php?id=80931&edit=1


Thread (35 messages)

« previous php.bugs (#245154) next »