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

From: Date: Tue, 13 Dec 2022 12:58:07 +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-243127@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:         jamie at hazaar dot io
 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:

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.


Previous Comments:
------------------------------------------------------------------------
[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.

------------------------------------------------------------------------
[2022-11-23 05:20:34] samira dot akhlaqi314 at gmail dot com

That's great. I was impressed by your writing. I am happy to see such a topic. Please come to
my blog and read it.

<https://www.subwaylistens.me/>/.php.net

------------------------------------------------------------------------
[2021-09-29 10:26:48] cmb@php.net

Related To: Bug #60465

------------------------------------------------------------------------
[2021-09-29 09:16:05] requinix@php.net

Related To: Bug #81487

------------------------------------------------------------------------
[2021-08-19 13:49:39] cmb@php.net

Related To: Bug #67352

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


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 (#243127) next »