Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep-alive for long-lived HTTP session (not persistent HTTP)

At work, we have a client-server system where clients submit requests to a web server through HTTP. The server-side processing can sometimes take more than 60 seconds, which is the proxy timeout value set by our company's IT staff and cannot be changed. Is there a way to keep the HTTP connection alive for longer than 60 seconds (preferably for an arbitrarily long period of time), either by heartbeat messages from the server or the client?

I know there are HTTP 1.1 persistent connections, but that is not what I want.

Does HTTP have a keep-alive capability, or would this have to be done at the TCP level through some sort of socket option?

like image 424
stackoverflowuser2010 Avatar asked Dec 03 '25 13:12

stackoverflowuser2010


1 Answers

Assuming you control both sides of the system, you can fake it by sending data back and forth periodically to keep the session from idling out -- most browsers won't terminate a connection as long as data is moving.

As a general suggestion, though, you're much better off re-designing the system so that the client submits a job request and then periodically queries (via Ajax) to see if it's completed. The Ajax queries can delay a while and the server can respond either when it has an affirmative status, or when the timeout period is near to elapsing. If the status-update request times out for some reason (timing errors or whatnot), the client simply re-submits it with no harm done and no visible disruption from the user's perspective.

like image 91
Dan Story Avatar answered Dec 05 '25 13:12

Dan Story



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!