Checking CURL Response for Errors in PHP
If some error occurs during the request,
the variable with the result will contain
false.
This can be used
to check for an error:
<?php
// Execute the request:
$res = curl_exec($curl);
if ($res === false) {
// Output an error message:
echo 'error';
} else {
// Output the result:
var_dump($res);
}
?>
Using the curl_error function,
you can get the text of the error
that occurred in CURL:
<?php
// Execute the request:
$res = curl_exec($curl);
if ($res === false) {
// Output the error:
echo curl_error($curl);
} else {
// Output the result:
var_dump($res);
}
?>
Make the appropriate corrections in your function.
Try to access a non-existent website. Study the CURL error text for this case.