如何管理要求的限制API调用 [英] How to manage request limited API calls

查看:188
本文介绍了如何管理要求的限制API调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是有这是在每个等级:IP 10秒30的处理请求新的限制TMDB的API。我可以通过在MySQL的一个表保存最后10秒,但每请求量跟踪这些电话我怎么能做到这一点的不同IP地址?

I am using tmdb API that has a new limit on requests which is 30 requests in 10 seconds per IP. I could track these calls by having a table in MySQL that holds the amount of requests per the last 10 seconds but how can I accomplish this with the different IP addresses?

我的应用程序的工作方式是:

The way my app works is:


  1. 请求从一个桌面应用程序的应用服务器进行。服务器端的PHP然后进行搜索,并返回数据。

  1. request is made to the application server from a desktop app. Server side php then makes a search and returns data.

桌面应用程序然后进行不同的调用应用程序服务器,并且轮流做几个API调用来TMDB(4-7)和其他的API。

desktop app then makes a different call to app server and that in turns makes several api calls to tmdb (4-7) and other api's.

有可从在一些情况下一些搜索请求到几千的任何地方。什么是跟踪和延缓API调用来保持低于限额的最佳方式?

There can be anywhere from a few search requests to a few thousands in some cases. What's the best way to keep track and delay api calls to keep it below the limit?

推荐答案

如果您的服务器发送请求,其中有一个限速另一台服务器,你需要一个全球的方法来跟踪请求从您的服务器,无论哪些客户是做请求到服务器等。

if your server is sending requests to another server which has a rate limit, you'll need a global way to keep track of requests from your server, regardless of which client is doing requests to your server etc.

我会用一个平面文件,并保存Unix时间,并为每个请求的分隔符,如果文件中包含这些十,你已经完成了10的请求,并且你需要清理文件,并删除任何时间戳这是年龄超过10秒钟,这会给你一个PHP率限制器的最简单的形式存在。

I would use a flat file, and save unix time and a delimiter for each request, and if the file contains ten of those, you've done ten requests, and you'll need to clean the file and remove any timestamp that is older than ten seconds, and that would give you the simplest form of a PHP rate limiter there is.

当然也有更先进的方式,但我会从那里开始,并确保您测试它,这样你就不会失去你的API访问权限等。

There are of course more advanced ways to this, but I'd start there, and make sure you test it so you don't loose your API access etc.

这篇关于如何管理要求的限制API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆