PHP implements a curl connection example with the retry function, and retries curl
This example describes how PHP implements curl connection with the retry function. We will share this with you for your reference. The details are as follows:
/*** @ Param string $ url access link * @ param string $ target: whether the returned result contains the $ target string * @ param int $ retry Number of retries, default 3 times * @ param int $ sleep Retry Interval, default 1 s * @ return bool | returned result of mixed curl * curlget with retry function of desc */function 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 whether the domain name is set in the certificate (it can be set to 0, that is, the existence of the domain name is not verified) $ output = curl_exec ($ ch); while (strpos ($ jsonOutput, $ target) === FALSE) & $ retry --) {// check whether $ targe has sleep ($ sleep); // Block 1 s $ output = curl_exec ($ ch);} curl_close ($ ch); return $ output ;}