Member-only story

Implementing a Rate Limiter with PHP

Atakan Demircioğlu
Jotform Tech
Published in
3 min readDec 7, 2022

In my previous article, I talked about ways to design a rate limiter to control network traffic. There are different algorithms that can be used to do this, and all have some pros and cons. Once you’ve chosen an algorithm and designed the system, it’s time to implement it with PHP.

I’ll talk about implementing a token bucket algorithm and creating a proof of concept (POC) within this article.

Let me know if you have any feedback in the comments.

Getting started

With a token bucket algorithm, we assume that we have a “bucket” that holds a set number of tokens. The capacity of the bucket is defined as the number of tokens that it can hold.

Whenever a consumer wants to access an API endpoint, it must get a token from the bucket. The token is removed from the bucket if it’s available and accepts the request. If the token is not available then the server rejects the request.

Let’s code

  • the prefix is for naming in the storage (we can have different rules & different routes)
  • the maxCapacity represents the maximum number of…

Published in Jotform Tech

Welcome to Jotform official tech blog. Read about software engineering and how Jotform engineers build the easiest form builder.

Written by Atakan Demircioğlu

Passionate about blogging and sharing insights on tech, web development, and beyond. Join me on this digital journey! 🚀

No responses yet

Write a response