PHP实现网站访问限速
我正在 LAMP 框架 + Codeigniter 上开发一个相当简单的网站,并希望实现用户访问速率限制功能,以防止该网站被单个用户的请求淹没。该网站的基本功能是接受代码输入并返回一些信息。
我仅处于规划阶段,我的第一个想法是拥有一个简单的数据库表,其中包含 IP 地址、上次访问时间戳和访问计数,但由于我的编码技能植根于非基于网络的应用程序,我将不胜感激任何想法完成此任务的最佳方法 - 例如,我是否应该考虑会话 ID 而不是 IP 地址,或者同时考虑 IP 地址?
我在一些常规网络搜索中没有找到太多信息,因此任何指示或指导都会很棒。
谢谢。
I am developing a fairly simple site on a LAMP framework + Codeigniter and want to implement a user access rate limit feature to prevent the site being flooded with requests from a single user. The basic function of the site is to take a code input and return some info.
I'm only at the planning stages and my first idea is to have a simple database table holding an IP address, last access timestamp and an access count, but as my coding skills are rooted in non web-based apps I would appreciate any thoughts on the best way to approach this task - for example, should I be considering session IDs instead of, or as well as, IP addresses?
I've not found much with some general Web searches so any pointers or guidance would be great.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您确实需要这样做,那么您最好在 PHP 参与之前就这样做。您可能会考虑考虑配置路由器或负载平衡器来执行此操作,或者至少配置某种 Web 服务器模块。
在 PHP 中执行此操作可能会产生过多的开销,甚至会弄巧成拙。
If you really need to do this, you're probably better off doing it before PHP even gets involved. You might consider looking into configuring a router or load-balancer to do this, or at the very least, some kind of web-server module.
Doing this in PHP is likely to create so much overhead as to be self-defeating.