Unfortunately, the other URLs of my csvarray don't get processed, because the script stops after this URL wih the redirection problem.
Your script doesn't stop because of the file_get_contents() redirection limit reached
error. file_get_contents()
triggers E_WARNING
which is non-fatal error and doesn't halt script.
My guess is that your script stops because of the maximum execution time limit or any other error. Put ini_set('display_errors', true);
and error_reporting(-1);
on the beginning of the file your call.
How can I just ignore this warning and continue with the next urls?
1. The easiest/noobish solution is to just ignore error with @
prefix.
$html = @file_get_contents('http://bit.ly/6wgJO');
2. You can increase/descrese max redirects for file_get_contents()
with 3rd parameter $context
(context options and parameters) :
$context = stream_context_create(['http' => ['max_redirects' => 50]]);
$html = @file_get_contents('http://bit.ly/6wgJO', false, $context);
3. Other solution of hiding errors is ignore_errors
in context options :
$context = stream_context_create(['http' => ['max_redirects' => 0, 'ignore_errors' => true]]);
$html = file_get_contents('http://bit.ly/6wgJO', false, $context);
- You can do magic with cURL.
- Set option
CURLOPT_FOLLOWLOCATION
to true
or false
if you wish to follow redirects.
- You can even set option
CURLOPT_MAXREDIRS
for number of maximum redirects to follow.
- Set option
CURLOPT_TIMEOUT
for maximum number of seconds to allow cURL functions to execute.
See other options here.