Answer the question
In order to leave comments, you need to log in
Why is recursion not working in php?
Hello.
Guys, help, it seems to be an easy task, but I can not solve it myself.
There is a code that pulls pages through url
function getData($url,$post=''){
$dir = dirname(__FILE__).'/cookie.txt';
$ch=curl_init();
$proxy = lastIp();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 35);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 35);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //Переходим по редиректам
curl_setopt ($ch , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
//curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_REFERER, "https://www.google.ru/");
curl_setopt($ch, CURLOPT_COOKIEJAR, $dir); // Записываем cookies в файл, чтобы потом можно было их считать
curl_setopt($ch, CURLOPT_COOKIEFILE, $dir); // Теперь читаем cookies с файла;
curl_setopt($ch, CURLOPT_USERAGENT, get_random_user_agent());
$res=curl_exec($ch);
curl_close($ch);
if(strlen($res)>0){
updateIp($proxy,'success');
return $res;
}else{
updateIp($proxy,'error');
logs('Bad proxy '.$proxy.' on url '.$url);
unset($res);
sleep(1);
getData($url);
logs('recursia not work');
return false;
}
}
Answer the question
In order to leave comments, you need to log in
Because in the else condition branch, the recursive function call does not return anywhere.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question