Bu şekilde olabilir;
function fetchData($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$response = curl_exec($ch);
$error = curl_errno($ch);
curl_close($ch);
if ($error) {
return fetchData($url)
}
return $response;
}