如何管理要求的限制API调用

编程入门 行业动态 更新时间:2024-10-25 06:20:38
本文介绍了如何管理要求的限制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:

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

  • 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调用

    本文发布于:2023-08-01 16:39:22,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1269921.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:API

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!