hirokws/callkeeper

Sequential API call/access rate keeper to be under limited rate.

1.0.3 2017-01-09 01:24 UTC

This package is not auto-updated.

Last update: 2024-12-16 15:08:04 UTC


README

Limit API calling to keep under limited rate per an unit time.

This implement is logic without using timer. So simple and light weight.

単位時間内でAPIの呼び出し回数を制限する。

タイマーを使用しない簡単なロジックで実装しているため、シンプルで軽い。

Laravelのワーカーとして利用するために開発したもの。APIコントロールは1常駐プロセスで行うと簡単に実現できる。

Usage

require __DIR__ . '/vendor/autoload.php';

use Callkeeper\Callkeeper;

...

/* Initialize */
$keep = new Callkeeper(3, 3000); // 3 times per 3,000 ms (3 seconds)

/* check and wait if needed */
$keep->limit();

$response = WebApiCalling(...);

...

Caution

This is simple keeper, so it is not thread safe. Also not async calling safe.

This is for sequential calling for single system from one process/thread.

License

MIT License.

Copyright reserved by Hirohisa Kawase.

Addition

Sorry for no test. It is hard to write tests for this type library... :P :D