开发者

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

开发者 https://www.devze.com 2022-12-25 04:13 出处:网络
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

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开发者_StackOverflow社区?

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?


This should get you started.


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.


Just have your server send a trickle of no-op data while it's doing the processing - if the result is in HTML, then something like:

<!-- keepalive -->

sent every 10 seconds should do.

0

精彩评论

暂无评论...
验证码 换一张
取 消