php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69461 No file_get_contents() timeout if follow_location=false
Submitted: 2015-04-15 10:17 UTC Modified: 2015-04-15 13:44 UTC
From: marc at gutt dot it Assigned:
Status: Open Package: Streams related
PHP Version: 5.4.39 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marc at gutt dot it
New email:
PHP Version: OS:

 

 [2015-04-15 10:17 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-15 10:18 UTC] marc at gutt dot it
Only for your information: This problem appears with PHP 5.3, 5.4 and 5.5.
 [2015-04-15 13:44 UTC] rdlowrey@php.net
-Package: URL related +Package: Streams related
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Dec 15 02:01:24 2019 UTC