0

may i consult this to you.. So This is my settings for every curl request i made..

 try{
    $ch = curl_init();
    if(strtoupper($method) == "POST" && $setParamsforPOST == true){
        $body = json_encode($body);
        curl_setopt( $ch, CURLOPT_POSTFIELDS, $body );
    }
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_URL, $curlUrl);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);

    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

   $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
   $data_curl = curl_exec($ch);

    curl_close($ch);

    return $data_curl;
 }catch(Exception $e){
    echo "An Error Has Encountered";
     header('X-PHP-Response-Code: 500', TRUE, '500');
    }

It works fine but in some scenarios it returns null response after 10 seconds.. But my timeout I set is actually 60 seconds as you see..

Logger:

//Works fine execution time : 3 sec

2017-12-06 09:08:48:06963100 => [3B07B7743F4EAD58CD] CURL Request: {{json data}}

2017-12-06 09:08:51:69533700 => [3B07B7743F4EAD58CD] CURL Response: {{json data}}

//Error.. Returning null after 10 sec

2017-12-06 08:51:35:74268300 => [F1461F1921E49ED226] CURL Request: {{json data}}

2017-12-06 08:51:45:94968500 => [F1461F1921E49ED226] CURL Response: null

  • is this all on the same url? –  Dec 06 '17 at 03:25
  • yeah right .. from our API .. but actually our API has a response after 24 sec.. but for every curl request greater than 10 seconds it returns null.. – gerger callanga Dec 06 '17 at 03:28
  • So I actually looking forward for the right settings of curl to achieve the 60 seconds timeout.. as you seen in the code.. – gerger callanga Dec 06 '17 at 03:29
  • take a look at **[this post](https://stackoverflow.com/questions/3757071/php-debugging-curl)** for tips on debugging cURL with php. It has helped me out many times. Also, what is `$httpcode`. If it is used you should get the curlinfo after the `curl_exec`. – YvesLeBorg Dec 06 '17 at 03:34

0 Answers0