Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

curl php loop

function Curl($url){
    $total_curl = 1;
    $isRunning = true;
    $sleep = 1;
    while ($isRunning){
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_REFERER, $this->url ?? $url);

        //for debug only!
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_TIMEOUT,10);

        $resp = curl_exec($curl);

        if((!$resp || curl_errno($curl))){
            if($total_curl > 3){
                $isRunning = false;
            }

            sleep($sleep);
        }

        curl_close($curl);
        $total_curl++;
    }
    
    return $resp;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #curl #php #loop
ADD COMMENT
Topic
Name
3+2 =