Здравствуйте! При запросе страницы через curl (php) иногда (не всегда) получаю ошибку "Recv failure: Connection reset by peer". Соединение сброшено сервером, но почему? | Код | function sendRequest($url, $cFile, $referer = '', $cookie = '', $post = array()) { $ua = 'Opera/9.80 (Windows NT 5.1; U; MRA 5.9 (build 4953); ru) Presto/2.9.168 Version/11.52'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); if ($referer != '') { curl_setopt($curl, CURLOPT_REFERER, $referer); } curl_setopt($curl, CURLOPT_USERAGENT, $ua); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_COOKIESESSION, TRUE); curl_setopt($curl, CURLOPT_COOKIEJAR, $cFile); curl_setopt($curl, CURLOPT_COOKIEFILE, $cFile); if ($cookie != '') { curl_setopt($curl, CURLOPT_COOKIE, $cookie); } $headers = array(); $headers[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; $headers[] = "Connection: keep-alive"; $headers[] = "Keep-Alive: 115"; $headers[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; $headers[] = "Accept-Language: en-us,en;q=0.5"; $headers[] = "Pragma: "; curl_setopt($curl, CURLOPT_ENCODING, 'gzip, deflate'); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); if (is_array($post) && count($post)) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); } else { curl_setopt($curl, CURLOPT_POST, 0); } $c = curl_exec($curl); echo curl_errno($curl).' - '.curl_error($curl).'<br><br>'; curl_close($curl); return $c; }
$cFile = ROOT_DIR.'cookies.txt'; //Сначала заходим на сам сайт $url = 'http://www.avito.ru/'; $c = sendRequest($url, $cFile);
|
|