Free proxies are hit or miss and regularly fail for one reason or another. Here is a function I use that will randomly try 2 proxies from an array of proxies looking for HTTP 200. As a last resort it uses anonymouse.org to get the file.
function proxy($url) {
$proxies = array();
$proxies[] = '1.1.1.1:80';
$proxies[] = '1.1.1.1:80';
$proxies[] = '1.1.1.1:80';
$proxies[] = '1.1.1.1:80';
$proxies[] = '1.1.1.1:80';
$proxies[] = '1.1.1.1:80';
$http=0;
$try=0;
while (true) {
$proxy = $proxies[array_rand($proxies)];
if (!function_exists('curl_init')) { die('Sorry cURL is not installed!'); }
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, "http://www.yomamma.com/");
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http==200) { break; }
$try++;
if($try>2) { break; }
}
if ($http!=200) {
$output=file_get_contents("http://anonymouse.org/cgi-bin/anon-www.cgi/$url");
}
return $output;
}
error_reporting(E_ALL);
? Otherwise hard to say, use curl alternatively. – mario