Both @Phliplip and @lunixbochs mentioned common cURL errors (maximum runtime and rejected by the target server.)
When sending many cURL requests to the same server, I try to "be beautiful" and set voluntary sleep periods so that I do not bombard the host. For a younger site, 1000+ queries may look like mini DDOS!
, . , NO.
<?php
header('Content-type: text/html; charset=utf-8', true);
set_time_limit(0);
$urls = array(
'http://www.example.com/cgi-bin/product?id=500',
'http://www.example.com/cgi-bin/product?id=501',
'http://www.example.com/cgi-bin/product?id=502',
'http://www.example.com/cgi-bin/product?id=503',
'http://www.example.com/cgi-bin/product?id=504',
);
$i = 0;
foreach($urls as $url){
echo $url."\n";
$curl = curl_init($url);
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($curl, CURLOPT_TIMEOUT, 25 );
$html = curl_exec($curl);
$html = @mb_convert_encoding($html, 'HTML-ENTITIES', 'utf-8');
curl_close($curl);
$i++;
if($i%10==0){
sleep(20);
} else {
sleep(2);
}
}
?>
:
, () .
" " , , :
$urls = array(
'http://www.example-one.com/',
'http://www.example-two.com/',
'http://www.example-three.com/',
'http://www.example-four.com/',
'http://www.example-five.com/',
'http://www.example-six.com/'
);
set_time_limit(0);, -, die; try
ini_set('display_errors',1);
error_reporting(E_ALL);
, .