The problem I am having is I am trying to do a curl request to a server, and I am getting redirected to a 504 page
I am trying to catch the error as follows:
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode==504){
header("Location: myOwnErrorPageFor504.php");
}
This code seems to catch other error codes, such as 200 perfectly fine. I think the problem is that as soon as it is 504, it redirects to that page or something before my code goes off to check if it returned a 504? I basically just want to do something if it returns 504.
I am using apache, and php 7.0 if this is relevant. This was the accepted answer to a couple other questions like this, but it doesnt work for me, so I am asking here.
Should note my apache specs. The timeout seems to be after around 50 seconds.
Timeout in my apache is 300. KeepAliveTimeout is 5.
For php:Default socket timeout 120.
So I don't know if its my server. Side not, this code is querying another server, which also queries another server after that. (its an API, that then queries another API, I didn't write it, thats just what it does).
For the person who wants the full curl code:
$ch = curl_init();
$headers = array(
'Content-Type: application/json',
$auth
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$ch_error = curl_error($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode==504){
curl_close($ch);
header("Location: contactUs.php");
}
if ($ch_error) {
curl_close($ch);
return $ch_error;
} else {
curl_close($ch);
return $result;
}