限制与 Web (http) 请求相关的数据库并发连接
我如何通过使用 php 限制传入连接的数量,使其不超过 1000(我认为这将为我的小型应用程序提供良好的性能),并且如果达到所述数量,则仅要求传入用户等待 x 时间?
到目前为止,我唯一想到的是添加一个具有多个连接的表,并在用户输入时减去 1,当计数器达到 0 时然后要求等待,但我认为应该有更好的方法。
How can I, by using php, limit the number of incoming connections so it doesn't exceed 1000 (which I think will allow good performance for my small app) and just ask incoming users to wait x time if said number is reached?
So far the only thing I've come up with is to add a table with a number of connections and substract 1 when a user enters and when that counter reaches 0 then ask to wait, but I think there should be a better way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTTP 是无状态的,也就是说不存在连接之类的东西。您需要某种会话处理系统并将其限制在那里。
HTTP is stateless, there is no such thing as a connection, per say. You need to have some sort of session handling system and limit it there.
如果您使用 MySQL,则有一个名为 max_user_connections 和 max_connections
但我不太确定这是否是您所需要的,或者如何知道何时达到限制。
If you're using MySQL there is an option called max_user_connections and max_connections
But I'm not really sure if it is what you need, or how to know when the limit is reached.