title: How to check API request timeout by using Curl?
body: <p>I have a scenario. Here I'm using Curl for accessing an API.
  If API is not accessible, I have to send an alert email. So how can I check, if there is a request timeout? </p>
  
  <p>Here is my code.</p>
  
  <pre><code>    $alerthttp1 = array();
      $string = 'somestring';
      $key = md5($string);
      $service_url = 'www.someurl.com/'.$key;
  
      $curl = curl_init($service_url);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_TIMEOUT, 300);
      $curl_response = curl_exec($curl);
      $curl_errno = curl_errno($curl);
      $curl_error = curl_error($curl);
  
      error_log(json_encode($curl_errno));
      error_log(json_encode($curl_error));
  
      if(curl_error($curl) || $curl_response === false || $curl_errno &gt; 0)
      {
          $info = curl_getinfo($curl);
          hlog_errorlog('error occured during curl exec - ' . var_export($info));
          hlog_errorlog('error -----------&gt; '. $curl_error); 
          curl_close($curl);
  
          $alerthttp1[] = array('status' =&gt; 'FAILED');//for email alert
      }
  </code></pre>
  
  <p>Please suggest me, the best way of coding. </p>
  
  <p>Thank you</p>