You start with $i=0, then you do $a+10 and $b+5 as long as $i <5
$i=0, $a=10, $b=5
$i=1, $a=20, $b=10
$i=2, $a=30, $b=15
$i=3, $a=40, $b=20
$i=4, $a=50, $b=25
$i=5, now the loop stops because $i is no longer <5
How does for loop works actually in php? - Stack Overflow
What is the best event loop extension for PHP 7.0 and greater?
I wrote a little function for Rate Limiting in PHP. Does the logic look sound? Comments welcome.
I tried using the Leaky Bucket and Token Bucket implementations but they space out the requests evenly
As author of bandwidth-throttle/token-bucket I'm very interested why token bucket did not work out for you. Could you please elaborate what you mean by "they space out the requests evenly"?
Still I would recommend using a token bucket (with a capacity of 30) for your API. Here's a short example with my library:
$storage = new SingleProcessStorage();
$rate = new Rate(30, Rate::SECOND);
$bucket = new TokenBucket(30, $rate, $storage);
$consumer = new BlockingConsumer(bucket);
$bucket->bootstrap(30);
while(true) {
$consumer->consume(1);
// Send SMS.
} More on reddit.com For $mysqli->query("SELECT * FROM table"); Why does PHP make you loop through results and call a "fetch" function on each one rather than just return an array with all of the results?
You can also use fetch_all.
As for why - what if your table had millions of records? Or each row had a 16 MB blob. Most database engines in any language will return a cursor which you must iterate to yield results.
More on reddit.comYou start with $i=0, then you do $a+10 and $b+5 as long as $i <5
$i=0, $a=10, $b=5
$i=1, $a=20, $b=10
$i=2, $a=30, $b=15
$i=3, $a=40, $b=20
$i=4, $a=50, $b=25
$i=5, now the loop stops because $i is no longer <5
Your loop runs five times. Each time through the loop you add 10 to the value of $a. Doing that five times gives you 50.