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;
    }
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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.