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:

curl.php<?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:

curl.php<?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);
  }
?>
Задание 1

Make the appropriate corrections in your function.

Задание 2

Try to access a non-existent website. Study the CURL error text for this case.