How can I make curl to pass the full request after a certain time?

There is a script it runs in the console, its task is to send a request to the API, get the response and save in dB.
Today I encountered a problem when sending the request, the server (where I send request) has not responded, so the script is fully stuck and had to start again.
I want to solve this problem by installing the curl

url_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); 
curl_setopt($ch, CURLOPT_TIMEOUT, 600); //10 minutes


The question how to handle this response if the script is again received no reply, he must not be closed, and begin to perform the following task.

If($response=="No answer"){
// the entry in log.txt
// write to dB skipping tasks
} // perform the following task
June 14th 19 at 20:19
1 answer
June 14th 19 at 20:21
Solution
Not sure that understood correctly, but maybe will help you:
try {
 $response = curl_exec($ch);
} catch (Exception $e) {
 echo 'No answer'.
}

//The next task.

Find more questions by tags APIPHP