Skip to content

Instantly share code, notes, and snippets.

View TomHAnderson's full-sized avatar
🏠
Working from home

Tom H Anderson TomHAnderson

🏠
Working from home
View GitHub Profile
@christeredvartsen
christeredvartsen / README.md
Created September 25, 2020 09:12
Simple retry strategy for Guzzle 7 when encountering "429 Too Many Requests" errors

Simple retry strategy for Guzzle 7

APIs might implement rate limiting, and if they do your clients might experience 429 Too Many Requests responses with a Retry-After header, informing your client how long it should wait before making the next request. And being good internet citizens we should all implement support for this in our API clients.

Guzzle includes a retry middleware class that can be used to handle this.

The implementation in this gist is a PoC, so feel free to build upon it, and comment if you think something should be added / removed.