如何在 php 中执行许多curl 请求时实践良好的道德规范

发布于 2024-11-24 19:40:33 字数 494 浏览 2 评论 0原文

我已经对此进行了大量阅读,但我不太确定正确的方法是什么。

我正在访问一个网站 api,它提供了我在网站上使用的信息。平均而言,我将发出超过 400 个不同的 API 请求,这意味着超过 400 个curl 请求。让我的代码暂停一段时间然后继续的正确方法是什么。该网站不限制点击量,因此我不会因为一次提取所有内容而被禁止,但当 10,000 个像我这样的人做同样的事情时,我不想成为那个服务器。我想做的是暂停我的代码并礼貌地使用他们提供的服务。

考虑到资源消耗,暂停 php 执行的最佳方法是什么?

每个等待周期最有礼貌的请求量是多少?

每个周期最有礼貌的等待时间是多少?

带着所有这些问题,我还想尽快获取信息,同时尝试解决上述问题。

evecentral API 响应示例

预先感谢您的时间和耐心。

I have done a fair amount of reading on this and I am not quite sure what the correct way to go about this is.

I am accessing a websites api that provides information that I am using on my site. On average I will be making over 400 different API requests which means over 400 curl requests. What is the proper way to make my code pause for an amount of time then continue. The site does not limit the amount of hits on so I will not get banned for just pulling all of the stuff at once, but I would not want to be that server when 10,000 people like me do the same thing. What I am trying to do is pause my code and politely use the service they offer.

What is the best method to pause php execution with resource consumption in mind?

What is the most courteous amount of requests per wait cycle?

What is the most courteous amount of wait per cycle?

With all of these questions I would also like to obtain the information as fast as possible while attempting to stay with in the above questions.

sample eve central API response

Thank you in advance for your time and patience.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戏舞 2024-12-01 19:40:33

这是一个想法:你问过吗?如果 API 在处理高负载时遇到困难,他们通常会在其条款中包含一个限制。如果没有,我建议向服务提供商发送电子邮件,解释您想要做什么,并询问他们认为合理的负载。尽管他们的服务器很可能能够处理您可能合理地想要提供的任何负载,这就是他们没有指定的原因。

如果您想让服务提供商做好事,就不要只是猜测他们想要什么。询问,然后您就会确切地知道在不让构建 API 的人感到不安的情况下您可以走多远。

对于暂停的实际机制,我将使用 alex 建议的 PHP usleep 方法(但已删除)。

Here's a thought: have you asked? If an API has trouble handling a high load, they usually include a limit in their terms. If not, I'd recommend emailing the service provider, explain what you want to do, and ask what they think would be a reasonable load. Though it's quite possible that their servers are quite capable of handling any load you might reasonably want to give it, which is why they don't specify.

If you want to do good by the service provider, don't just guess want they want. Ask, and then you'll know exactly how far you can go without upsetting the people who built the API.

For the actual mechanics of pausing, I'd use the method alex suggested (but has since deleted) of PHP's usleep.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文