Released: Retry anything in PHP

Jan Machala
Aug 1, 2017 · 1 min read
Simple try again same API call when error occurs

After the first naive version of Retry in PHP i’ve come up with much better solution, which fits our need in Bileto Technologies.

Network connection could break, 3rd party application could be down for a while a, of course, you messaging service could break. This happens to us sometimes, but when it happens, we should be prepared for that.

I’ve come up with a simple function, which could retry your calls based on failure conditions you specify. Failure conditions could be based on returned value, exceptions thrown from the function or on the combination of both. Down here is an example of one case for our RabbitMQ service calls:

As you can see, when AMQPRuntimeException or AMQPProtocolException comes up we retry sending the message again to RabbitMQ. In other cases, we want to let it fail, i.e. when some sort of InvalidArgumentException and other errors occur.

We use it also for mail calls, logging service, algolia api and for SMS provider. We have in plan to use it of online payment gateways like GoPay, PayU, Tatrabank and CSOB.

Check out small package on to see more examples and try it in you application. Please give me a feedback how do you feel about this package.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade