Answer the question
In order to leave comments, you need to log in
PHP CURL: How to re-curl if I get a 503 code (see inside)?
The server with frequent requests gives the 503rd code.
If you repeat after 3 seconds, you can parse again.
This code throws an error (error text below the code):
function get_url($href) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $href);
curl_setopt($curl, CURLOPT_REFERER, $href);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT, "my_useragent_string");
$str = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($httpcode == '503') {
curl_close($curl);
sleep(4);
$this->get_url($href);
}
curl_close($curl);
return $str
}
Answer the question
In order to leave comments, you need to log in
So 403 or 503?
if ($httpcode == '503') {
curl_close($curl);
sleep(4);
$this->get_url($href);
}
curl_close($curl);
you do curl_close twice.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question