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 github.com to see more examples and try it in you application. Please give me a feedback how do you feel about this package.