file_get_contents, failed to open stream: Redirection limit reached
$param = $_REQUEST;
$oAuthToken = $param['oAuthToken'];
$fileId = $param['fileId'];
$getUrl = 'https://www.googleapis.com/drive/v2/files/' . $fileId . '?alt=media';
$authHeader = 'Authorization: Bearer ' . $oAuthToken;
ini_set('memory_limit', '512M');
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $getUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
$authHeader
));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$data = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
file_put_contents($param['name'], $data);
this is the solution i found
PHP - failed to open stream : redirection limit reached
Try to use this code, which won't follow the redirects automatically:
$context = stream_context_create(
array(
'http' => array(
'follow_location' => false
)
)
);
$html = file_get_contents('YOUR_URL', false, $context);
The other problem is that the URL you are trying to get content from returns a 404 error.
php: Redirection limit reached
I used curl instead:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.oref.org.il/WarningMessages/Alert/alerts.json?v=1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, '3');
$content = curl_exec($ch);
curl_close($ch);
PHP fopen() Redirection Limit Reached Error
Where are the files located you are trying to open? Are they on the local filesystem or are you trying to access them via HTTP(S)?
If you're using some network protocol wrapper then, this error is most likely connected with too many (HTTP - in case of the HTTP(S) protocol) redirects on the way from your script to the file you want to open. The default redirection limit should be 20. As 20 redirects are quite alot there could be some error in the filename itself (causing e.g. the webserver on the other end to do some spellcheck-redirects) or the other server is misconfigured or there are some security measures in place or...
If you feel the need to extend the 20 redirects you could use a stream context.
$context = array(
'http'=>array('max_redirects' => 99)
);
$context = stream_context_create($context);
// hand over the context to fopen()
$fp = fopen($file, 'r', false, $context);
// ...
Please see:
- Streams
stream_context_create()
- HTTP context options
file_get_contents' function from multiple URLs and redirection limit reached warning
I would suggest using cURL for fetching remote data. You could do this:
$urls = [
"https://www.url1.com",
"https://www.url2.com",
"https://www.url3.com",
"https://www.url4.com",
"https://www.url5.com"
];
$decoded = array_map("loadJSON", $urls);
if (is_array($decoded[0])) {
foreach ($decoded[0] as $key => $value) {
if (is_array($value) && isset($value['price'])) {
$price = $value['price'];
echo '<span><b>' . $price . '</b><span>';
}
}
}
/**
* Downloads a JSON file from a URL and returns its decoded content
*/
function loadJSON($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // If your server does not have SSL
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Follow redirections
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); // 10 max redirections
$content = curl_exec($ch);
curl_close($ch);
$res = json_decode($content, true);
return $res;
}
get_headers() Redirection limit reached, aborting. failed to open stream: Operation now in progress
This website is broken, because your client function does not handle session IDs it will keep redirecting to itself. Use a fully fledged HTTP client.
HEAD -eS http://webtrh.cz/66997-fakturace-ramci-dph?p=416206
HEAD http://webtrh.cz/66997-fakturace-ramci-dph?p=416206 --> 301 Moved Permanently
HEAD http://webtrh.cz/66997-fakturace-ramci-dph?s=6e10b6d98d94e570cce1267cff4cbefb&p=416206 --> 301 Moved Permanently
HEAD http://webtrh.cz/66997-fakturace-ramci-dph?s=8989dd7c5daad97e23ca77b1ccadde06&s=6e10b6d98d94e570cce1267cff4cbefb&p=416206 --> 301 Moved Permanently
HEAD http://webtrh.cz/66997-fakturace-ramci-dph?s=a3defbb086f1810cc45df07b6669b961&s=8989dd7c5daad97e23ca77b1ccadde06&s=6e10b6d98d94e570cce1267cff4cbefb&p=416206 --> 301 Moved Permanently
HEAD http://webtrh.cz/66997-fakturace-ramci-dph?s=111a329fc1632272a0403db172579199&s=a3defbb086f1810cc45df07b6669b961&s=8989dd7c5daad97e23ca77b1ccadde06&s=6e10b6d98d94e570cce1267cff4cbefb&p=416206 --> 301 Moved Permanently
HEAD http://webtrh.cz/66997-fakturace-ramci-dph?s=318e7bc7ab78e5a2f96acddd6f84147c&s=111a329fc1632272a0403db172579199&s=a3defbb086f1810cc45df07b6669b961&s=8989dd7c5daad97e23ca77b1ccadde06&s=6e10b6d98d94e570cce1267cff4cbefb&p=416206 --> 301 Moved Permanently
HEAD http://webtrh.cz/66997-fakturace-ramci-dph?s=7679f6fbe731aef1ccfbc9550535bc9c&s=318e7bc7ab78e5a2f96acddd6f84147c&s=111a329fc1632272a0403db172579199&s=a3defbb086f1810cc45df07b6669b961&s=8989dd7c5daad97e23ca77b1ccadde06&s=6e10b6d98d94e570cce1267cff4cbefb&p=416206 --> 301 Moved Permanently
HEAD http://webtrh.cz/66997-fakturace-ramci-dph?s=427b87ff88b92928bc96f3464c64411f&s=7679f6fbe731aef1ccfbc9550535bc9c&s=318e7bc7ab78e5a2f96acddd6f84147c&s=111a329fc1632272a0403db172579199&s=a3defbb086f1810cc45df07b6669b961&s=8989dd7c5daad97e23ca77b1ccadde06&s=6e10b6d98d94e570cce1267cff4cbefb&p=416206 --> 301 Moved Permanently
Cache-Control: private, post-check=0, pre-check=0, max-age=0
Connection: close
Date: Tue, 29 Dec 2009 15:48:47 GMT
Pragma: no-cache
Location: http://webtrh.cz/66997-fakturace-ramci-dph?s=39c9ebd344b1a1b473fcba1dcaab38f8&s=427b87ff88b92928bc96f3464c64411f&s=7679f6fbe731aef1ccfbc9550535bc9c&s=318e7bc7ab78e5a2f96acddd6f84147c&s=111a329fc1632272a0403db172579199&s=a3defbb086f1810cc45df07b6669b961&s=8989dd7c5daad97e23ca77b1ccadde06&s=6e10b6d98d94e570cce1267cff4cbefb&p=416206
Server: Apache/2.2.3 (CentOS)
Content-Type: text/html; charset=UTF-8
Expires: 0
Client-Date: Tue, 29 Dec 2009 15:48:17 GMT
Client-Response-Num: 1
Client-Warning: Redirect loop detected (max_redirect = 7)
Set-Cookie: bbsessionhash=39c9ebd344b1a1b473fcba1dcaab38f8; path=/; domain=.webtrh.cz; HttpOnly
Set-Cookie: bblastvisit=1262101727; expires=Wed, 29-Dec-2010 15:48:47 GMT; path=/; domain=.webtrh.cz
Set-Cookie: bblastactivity=0; expires=Wed, 29-Dec-2010 15:48:47 GMT; path=/; domain=.webtrh.cz
X-Powered-By: PHP/5.1.6
X-UA-Compatible: IE=7
TYPO3 v7.6.19: solr PHP Warning: failed to open stream: Redirection limit reached
Solved it. It was a Content Element which is connected to OAuth2. For some reason Ext:solr does a call to Custom Content Element to parsing it. So every time it try´s to call it, it gets redirected in a loop. So to solve it i used the Headers. If Typo3 header is called and not a browser it should not parse this Content Element.
So i just removed this Element from parsing it.
Related Topics
PHP Warning: PHP Startup: Unable to Load Dynamic Library 'Pdo_Mysql.So'
Mysqli Commands Out of Sync; You Can't Run This Command Now
How to Download Blob Based File from MySQL Database in PHP
How to Detect If Your Website Visitor Came from a Google Search Result
How to Get the List of Available Locales in PHP
How to Add a View Helper Directory (Zend Framework)
Is There a Call_User_Func() Equivalent to Create a New Class Instance
Laravel Change Connection Dynamically
Convert Unicode to HTML Entities Hex
Good Tutorial on How to Update Your MySQL Database with a PHP Form
Strip HTML Tags and Its Contents
Fatal Error: Uncaught Argumentcounterror: Too Few Arguments to Function
Simple PHP Mail Function Not Working on Amazon Server Ec2
PHP Preg-Replace More Than One Underscore
Interpreting Return Value of Function Directly as an Array
MySQL Stored Function to Create a Slug