Bug #43098 [Com]: file_get_contents() freezes (probably caused by fopen())

From: Date: Fri, 05 Sep 2014 17:21:08 +0000
Subject: Bug #43098 [Com]: file_get_contents() freezes (probably caused by fopen())
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187431@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=43098&edit=1

 ID:                 43098
 Comment by:         f dot eeprom at gmail dot com
 Reported by:        harvie at email dot cz
 Summary:            file_get_contents() freezes (probably caused by
                     fopen())
 Status:             No Feedback
 Type:               Bug
 Package:            HTTP related
 Operating System:   Linux (Debian Etch) - php5-cli
 PHP Version:        5.2.4
 Block user comment: N
 Private report:     N

 New Comment:

It still happens. PHP 5.3.10 here.

I have a script that keeps polling data from an online API every 10 seconds. After some days or
normal function, it freezes at file_get_contents() even with the timeout parameter set to 10 in the
http options. It often happens after/during connection problems with the server.

    protected function retrieveJSON($URL) {
        $opts = array('http' =>
            array(
                'method' => 'GET',
                'timeout' => 10,
            )
        );
        $context = stream_context_create($opts);
        $feed = file_get_contents($URL, false, $context); <--- FREEZE
        $json = json_decode($feed, true);
        return $json;
    }


Previous Comments:
------------------------------------------------------------------------
[2013-02-18 00:33:53] php-bugs at lists dot php dot net

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.

------------------------------------------------------------------------
[2010-11-24 09:19:38] jani@php.net

Does it happen with PHP 5.3.3? I still can not reproduce it.

------------------------------------------------------------------------
[2010-03-02 21:49:13] dyekimov at uniplat dot ru

So, has anyone found a way out of this problem?

Is it a known bug?

------------------------------------------------------------------------
[2007-10-26 10:49:02] harvie at email dot cz

Yeah! Thats what i need... Something like default_poll_timeout setting...

------------------------------------------------------------------------
[2007-10-26 10:40:18] harvie at email dot cz

jani@php.net: That is what i am saying, this will never comes to next iteration. If i wan't to
do some kind of error check, it will never be executed, because whole program will stop at
file_get_contents() and will not execute anything after this call. Thats the problem. This function
will never return anything.

With this timeout, this script have to print '#' at least once a second.

But the default_socket_timeout stops waiting for connection but in this case the
file_gets_contents() is already downloading when server drops the connection because of network
unstability or service overload.

Isn't there some kind of timeout, that will stop waiting for broken connection after specified
time?

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


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=43098


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


Thread (13 messages)

« previous php.bugs (#187431) next »