0

I am receiving a response from using a curl request. But how do I check whether my curl request throws an error or not? because it takes 15 minutes to give a response from API.(but it works fine while testing in postman)

Can anyone guide me to solve this?

public function getDynamicPriceFromErp($sku, $priceCode)
 {
 $url = "https://v3.test.com/v1/test/44gggttfff234";
 $this->curlClient->setOption(CURLOPT_HEADER, 0);
 $this->curlClient->setOption(CURLOPT_TIMEOUT, 2000);
 $this->curlClient->setOption(CURLOPT_RETURNTRANSFER, true);
 //set curl header
 $this->curlClient->addHeader("Content-Type", "application/json");
 $this->curlClient->addHeader("Authorization", "Bearer fhY0eXAigoY");
 //post request with url and data
 $this->curlClient->post($url);
 //read response
 $response = $this->curlClient->getBody();
 return $response;
 }
asked Jan 22, 2021 at 2:45

1 Answer 1

0

This is natural behaviour of an API call. It waits for server response. I have faced the same situation. I solved using CURLOPT_CONNECTTIMEOUT in my code. This will stop execution after 10 seconds if no response from API. Hope it help someone

$this->curlClient->setOption(CURLOPT_CONNECTTIMEOUT, 10);

answered Jan 22, 2021 at 8:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.