This post will talk about a pattern I started to use when working with an asynchronous job queue in PHP. During my time developing this pattern I went from initially using a typical Relational Database like MySQL to eventually converting the data storage to use a service like SQS. In any case the data storage mechanism is not pertinent to what I will be discussing. What is important is that the storage mechanism must support a queue feature called a dead-letter queue. For those unfamiliar a dead-letter queue is an entirely separate queue from your primary one in which we store jobs that for one reason or another have simply failed. It is typical to have a system retry a job a few times but eventually it might decide to delete the original message and store a new one in the dead letter queue. What makes it dead you ask? Jobs in a dead letter queue will just sit there until you manually run them. Manually running them lets us begin a debugging session where we will observe as they run following up with a debug session to resolve the issue. Hopefully the behavior that caused the problem will come up again when you run the job manually so that you can make the needed changes to fix the problem for good.
Error Handling
It's typical for a PHP project to be serving a website or an API. Those who are new to the ecosystem might do a simple echo to send that text to the browser and intermingle their PHP with HTML or even return parts of the