views:

55

answers:

3

I planning to release an Api for public. what I am looking into is since it is free I need to control the usage. there are couple of options in my mind. one is delay number of queries per second. second one is fix queries to certain number per day. but second option seems to do more work on scripting which I am planning to avoid now.

so my question is how can I delay number of queries per second limit to 2 and rest put in Queue.

I am working on php so the same script would be appreciated.

or else any other suggestions welcome

A: 

You can use php's sleep function to hold the execution in terms of time.

$query = "....................";

// wait for 10 seconds
sleep(10);

// Then execute
$result = mysql_query($query);

//queue other queries in the same way
Starx
this will leave the php process hanging for a (potentially) long time.
kgb
A: 

Why don't you use cron for time/resource critical queries? You can fine-tune your settings at anytime to fit your needs at the best.

fabrik
actually the OP is trying the delay the execution, not execute a job without user interaction
Starx
And that was why you downvoted my answer? Nice.
fabrik
Yes, Fabrik, I did downvote this answer because it does not answer the OP's question but provides an alternative method.
Starx
A: 

The second idea is for me the better one. You could write in a table, how many queries are done today and then see how many you could do. If you have already done the numer of queries you want then you cold stop und give a message.