Bug #69461 [Opn->Fbk]: No file_get_contents() timeout if follow_location=false
| From: | cmb@php.net | Date: | Tue, 27 Jul 2021 14:12:10 +0000 |
| Subject: | Bug #69461 [Opn->Fbk]: No file_get_contents() timeout if follow_location=false | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235407@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69461&edit=1
ID: 69461
Updated by: cmb@php.net
Reported by: marc at gutt dot it
Summary: No file_get_contents() timeout if
follow_location=false
-Status: Open
+Status: Feedback
Type: Bug
Package: Streams related
Operating System: Debian
PHP Version: 5.4.39
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Does this still happen with any of the actively supported PHP
versions[1]?
[1] <https://www.php.net/supported-versions.php>
Previous Comments:
------------------------------------------------------------------------
[2015-04-15 10:18:53] marc at gutt dot it
Only for your information: This problem appears with PHP 5.3, 5.4 and 5.5.
------------------------------------------------------------------------
[2015-04-15 10:17:45] marc at gutt dot it
Description:
------------
I loaded several thousand http/https URLs through file_get_contents(). By that a very tiny amount of
URLs did not respect the timeout setting of file_get_contents() and not the PHP max_execution_time
as well. It results after 10 minutes an Internal Server Error.
The problematic URL is a https://-URL that answers with a 301 redirect to
a http://-URL. I tested it through cURL
(CURLOPT_FOLLOWLOCATION=false,CURLOPT_SSL_VERIFYPEER=0), and this was the answer:
###############################################
string(138) "HTTP/1.1 301 Moved Permanently
Location: http://www.example.com/
Content-Length: 0
Content-Type: text/html; charset=UTF-8
"
###############################################
More details here:
http://stackoverflow.com/q/29628594/318765
Test script:
---------------
this results "Internal Server Error"
###############################################
$context = stream_context_create(array(
'http' => array(
'follow_location' => false,
'timeout' => 2,
),
'ssl' => array(
'verify_peer' => false,
),
));
echo file_get_contents($url, false, $context);
###############################################
this returns "Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error
messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in
/usr/www/users//t051.php on line 12":
###############################################
'verify_peer' => true,
###############################################
And now the strange part. This returns the website?!
###############################################
$context = stream_context_create(array(
'http' => array(
'follow_location' => true,
'timeout' => 2,
),
'ssl' => array(
'verify_peer' => false,
),
));
echo file_get_contents($url, false, $context);
###############################################
Expected result:
----------------
As verify_peer and follow_location are set to false it should return the websites header.
Actual result:
--------------
It returns "Internal Server Error 500" after 10 minutes.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69461&edit=1