This article describes the PHP implementation with retry function Curl connection method. Share to everyone for your reference, specific as follows:
/**
* @param string $url Access Link
* @param string $target criteria to retry: Returns whether the result contains a $target string
* @param int $retry retry times Number, default 3 times
* @param int $sleep retry interval, default 1s
* @return bool|mixed Curl return results
* desc have retry curlget * *
Functi On Curlgetretry ($url, $target, $retry =3, $sleep = 1)
{
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_connecttimeout, 5);
curl_setopt ($ch, Curlopt_timeout, 5);
curl_setopt ($ch, Curlopt_ssl_verifypeer, false); Trust any certificate
curl_setopt ($ch, Curlopt_ssl_verifyhost, 1);//Check the certificate to set the domain name (0 is also OK, even if the domain name exists or not verified)
$output = Curl_ EXEC ($ch);
while (Strpos ($jsonOutput, $target) = = FALSE) && $retry-) {//check $targe for Sleep
($sleep);//block 1s
$ Output = Curl_exec ($ch);
}
Curl_close ($ch);
return $output;
}
More about PHP Interested readers can view the site topics: "Php Curl Usage Summary", "PHP array" operation Skills Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", " PHP Programming algorithm Summary, "PHP Mathematical Calculation Skills Summary", "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.