I collect data from a website that, sometimes, seems to be not accessible (or, maybe it’s just the DNS host that has sometimes some issues).
The program written in PHP (launched with CLI) quits with the error:
Couldn’t resolve host ‘abcdef.com’
I would like to intercept this error, like with an exception, because the program must not quit.
I tried a “try catch” but this doesn’t work.
I would like to avoid the use of an external daemon to restart the program…
Thank you for your help.
EDIT :
The code used :
function goToPage($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, realpath("./cookies/cookie.txt"));
$ret = curl_exec($ch);
if ($ret === FALSE) {
die(curl_error($ch));
}
curl_close($ch);
$this->delay();
return $ret;
}
Are you sure that it is actually stopping the execution of your program? I mean, if it’s not an Exception… it’s not an Exception. As far as I know, cURL doesn’t throw any Exceptions or fatal errors. What you’re seeing is most likely just a regular notice / warning. To figure out whether or not you have cURL errors, you can just use the functions curl_errno() and curl_error():
Or, if you want to throw a custom Exception: