405 nginx/ 499 HTTP - timeout issue between a php and a rails service

i like this post (click again to cancel)
0
i dont like this post (click again to cancel)

Hi,

I have the following configuration on dotcloud:

  • 1 PHP Service where I host a website (nginx, php-fpm, fastcgi) - the client

  • 1 Rails Service where I host the backend - the server

Problem: I have a particular request that does some processing in the backend. The client(PHP) sends the request to the server(Rails) and is blocking until the process is executed in the backend (which is normal). The problem is that after a certain time (aprox 80s) the website redirects me to a page 405 Not Allowed Nginx. In the access logs of both the PHP and Rails service I have a 499 status code for the request - which obviously means that the client disconnected (aka the PHP service I guess)

10.44.133.106 (::ffff:184.73.28.59) - - [13/Feb/2012:14:36:17 +0000] "POST 
/81af8ebb1836515da3f87a9ec5ca4de418ddbdd7/documents.xml HTTP/1.0" 499 0 "URL OF 
THE BACKEND web service" "-"

On top of this in the logs of the Rails service I also get:

[ pid=58 thr=140045320689408 file=ext/nginx/HelperAgent.cpp:566 time=2012-02-13
14:37:09.107 ]: Couldn't forward the HTTP response back to the HTTP client: It 
seems the user clicked on the 'Stop' button in his browser.

I've set the following variables in nginx.conf in the hope that will solve something but it didn't. The moment when the PHP Service stops waiting for a response is constant at around 80 sec.

client_header_timeout 200;
client_body_timeout 200;
send_timeout 200;
fastcgi_read_timeout 200;

Any ideas are appreciated. Thanks.

asked Feb 13 '12

doctrackr gravatar image doctrackr
3 1 1 4

As you've noted, 499s occur when a client disconnects from Nginx before it has had the chance to return a response. It sounds, then, like your PHP process is disconnecting before processing has completed. What are you using on the PHP side to connect to the server? curl?

gabriel (Feb 14 '12)

To clarify: is that first log output coming from the Rails or PHP side?

gabriel (Feb 14 '12)
i like this answer (click again to cancel)
0
i dont like this answer (click again to cancel)

Hey!

As you've noted, 499s occur when a client disconnects from Nginx before it has had the chance to return a response. It sounds, then, like your PHP process is disconnecting before processing has completed.

If you're using curl from PHP to create your connection, you might want to try using the curl_setopt() function to set the CURLOPT_TIMEOUT option and see if it helps.

I'm a little skeptical that this will work, though, because I believe that if no CURLOPT_TIMEOUT option is set, it should default to never timing out.

A better long-term solution would be to not rely on the connection remaining open indefinitely, and return a response after, say, 30 seconds that instructs the client to reconnect to continue waiting on the response. Obviously this is a bit more tricky to implement, though.

link

answered Feb 14 '12

gabriel gravatar image gabriel
71 7

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

1 follower

Tags:

Stats:

Asked: Feb 13 '12

Seen: 1,302 times

Last updated: Feb 14 '12

Powered by Askbot version 0.7.23

Copyright DotCloud, 2011. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.