2

Look the following PHP code:

$start = time();

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://gmaxil.com'); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Java/1.7.0_60');
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);

$end = time();

var_dump(curl_error($ch));
var_dump($end-$start);

curl_close($ch);

Running it on the local GAE environment (my machine), I get the following response (~2 seconds later):

string(43) "Resolving timed out after 2529 milliseconds" int(2)

Running it on GAE remote environment, I get the following response (~40 seconds later):

string(34) "Couldn't resolve host 'gmaxil.com'" int(40)

Why is Google App Engine ignoring the cURL timeout option?

Lucas NN
  • 758
  • 5
  • 16
  • I'm guessing that it's not ignoring the timeout -- because it's not timing out. It's just immediately failing. – Alex Howansky Apr 26 '17 at 20:19
  • @AlexHowansky But Why am I having different behavior between the local and production environments? – Lucas NN Apr 26 '17 at 20:21
  • Because local has working DNS. Remote has broken DNS that immediately fails. (Again, that's a guess...) – Alex Howansky Apr 26 '17 at 20:22
  • @AlexHowansky I believe you didn't understood. The timeout in my local machine works very well, it stops the cURL in ~2 seconds, but when running the code in GAE, it doesn't stop de cURL, it takes 40 seconds to fail. This is not desirable. – Lucas NN Apr 26 '17 at 20:24
  • _"it takes 40 seconds to fail."_ Ah. You did not mention that important little tidbit in your post. – Alex Howansky Apr 26 '17 at 20:25
  • Ah ok I see now, it's in the `var_dump()` – Alex Howansky Apr 26 '17 at 20:25
  • @AlexHowansky Look the GAE response: `int(40)`. Sorry, I will be more clear in the question. – Lucas NN Apr 26 '17 at 20:26

1 Answers1

1

Please check this link. PHP cURL: CURLOPT_CONNECTTIMEOUT vs CURLOPT_TIMEOUT

CURLOPT_TIMEOUT is the maximum time that you allow the libcurl to transfer the data to server, this doesn't mean that the server is going to respond in the timeout that you set.

Community
  • 1
  • 1
Marcell Rico
  • 169
  • 2
  • 5