开发者

how to practice good ethics while executing many curl requests in php

开发者 https://www.devze.com 2023-03-20 18:55 出处:网络
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 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 questio开发者_如何转开发ns 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号