0

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

enter image description here

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;
}
Lain
  • 2,166
  • 4
  • 23
  • 47
  • 2
    It might be your server returning a 504, not the remote server. – aynber Apr 30 '19 at 15:24
  • Indeed, I should post my specs. I did think of this – Lain Apr 30 '19 at 15:24
  • You should post your full curl code – Patrick Q Apr 30 '19 at 15:35
  • @PatrickQ Done. – Lain Apr 30 '19 at 15:43
  • I'm with aynber, looks like the timeout is probably on _your_ server. – Patrick Q Apr 30 '19 at 15:45
  • @PatrickQ So how do I go about debugging this then? What I searched on timeouts were the things I posted. Its still the same problem I am trying to solve. Do something instead of 504. – Lain Apr 30 '19 at 15:48
  • @aynber Is there a solution to this? I also conclude it might be. However does not change that I would like to do something instead of time out. – Lain Apr 30 '19 at 16:01
  • @Lain Unfortunately, that is kind of hard to debug remotely. Just to confirm, even though you say "I am getting redirected to a 504 page", you're not actually getting _redirected_, right? You're staying on the same URL, you just see the error message as the output/response of your request? – Patrick Q Apr 30 '19 at 16:02
  • Try setting `CURLOPT_CONNECTTIMEOUT` on your connection to a value smaller than your server/php timeout. That way the curl script will time out before your script. – aynber Apr 30 '19 at 16:03
  • @PatrickQ that is correct. Not redirected – Lain Apr 30 '19 at 16:06
  • @aynber Didn't seem to do anything. Still timed out after 50 seconds. Added both of these curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); curl_setopt($ch, CURLOPT_TIMEOUT, 15); Both individually and together. No luck. – Lain Apr 30 '19 at 16:18

1 Answers1

0

Spring Data JPA by default looks for an EntityManagerFactory named entityManagerFactory. Check out this part of the Javadoc of EnableJpaRepositories or Table 2.1 of the Spring Data JPA documentation.

That means that you either have to rename your emf bean to entityManagerFactory or change your Spring configuration to:

(if you are using XML)

or

@EnableJpaRepositories(basePackages="your.package", entityManagerFactoryRef="emf")

(if you are using Java Config)

nessrine
  • 1
  • 1