我可以从 C 模块内部强制关闭 Apache 2.2 连接吗?
我们希望对 C++ Apache 2.2 模块(在 CentOS 5 上)中提供的连接进行更细粒度的控制。
其中一个连接需要在几个多个请求中保持活动状态,因此我们将“KeepAlive”设置为“On”并设置较短的保持活动时间。
但是对于每个这样的连接,我们都会有更多来自浏览器的连接,我们不需要留下这些连接,而是希望在单个请求后强制它们关闭。
其中一些连接位于不同的端口上(因此我们可以通过端口来区分它们,因为可以为每个虚拟主机设置 KeepAlive),而另一些则请求不同的 URL(因此我们可以从路径和参数中看出我们不想离开他们在后面)。
另外,对于我们确实想要保持活动状态的对象,我们知道在收到某个请求后我们也想将其关闭。
但到目前为止,我们发现“取消”保持活动的唯一方法是向客户端发送礼貌的“Connection:close”标头。如果客户行为不端或恶意,那么他们可以保持开放并浪费我们的资源。
有没有办法告诉Apache从服务器端关闭连接?该文档建议不要在套接字上进行简单的 close(2) 调用,因为 Apache 需要在此之前进行一些清理工作。但是是否有一些 API 或技巧可以动态“覆盖”静态“KeepAlive On”配置(并说服 Apache 调用 close(2))?
谢谢。
We'd like to have a more fine-grained control on the connections we serve in a C++ Apache 2.2 module (on CentOS 5).
One of the connections needs to stay alive for a few multiple requests, so we set "KeepAlive" to "On" and set a short keep-alive period.
But for every such connection we have a few more connections from the browser which we don't need to leave behind and instead want to force them to close after a single request.
Some of these connections are on different ports (so we can distinguish them by port, since KeepAlive can be set per virtual host) and some request a different URL (so we can tell from the path and parameters that we don't want to leave them behind).
Also for the one we do want to keep alive, we know that after a certain request we'd like to close it too.
But so far the only way we found to "cancel" the keep-alive is to send a polite "Connection: close" header to the client. If the client is not well behaved, or malicious, then they can keep it open and waste our resources.
Is there a way to tell Apache to close the connection from the server side? The documentation advises against just plain close(2) call on the socket since Apache needs to do some clean up before that's done. But is there some API or a trick to "override" the static "KeepAlive On" configuration dynamically (and convince Apache to call close(2))?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试设置c->aborted,那么apache将在有序关闭期间在正确的时间关闭套接字。
Try setting c->aborted, then apache will close the socket at the right time during its orderly shutdown.