I'm working with a third party API, and it returns 400 HTTP STATUS when you make a mistake. When using POSTMAN, the 400 HTTP error page shows as expected, but when using PHP's cURL, the page just loads for about a minute, then it gives me a "504 - Gateway timeout", and I need to close the browser to be able to access the page again. When the cURL request is valid (the API returns a 200 OK) it works normally.
My question is, why is cURL giving the 504 error instead of 400? And why is it ignoring CURLOPT_CONNECTTIMEOUT and CURLOPT_TIMEOUT?
Below is my cURL code (both $token, $payload and $config variables are declared and valid):
$ch = curl_init("https://api.mercadolibre.com/items?access_token=$token"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "User-Agent: Alcavie/" . $config['version'], "Accept: application/json", "Content-Type: application/json", //"Accept-Encoding: gzip, deflate, br", //"Connection: keep-alive" )); $error = false; try{ $result = curl_exec($ch); $resultJson = json_decode($result); }catch(\Exception $e){ var_dump($e); $error = true; exit; } curl_close($ch);