Symfony Doctrine Messenger

Hi folks.
I maintain a Laminas MVC project which has a small number of users but due to significant increase in transactions, the amount of data has also grown and the reports that are being generated are currently taking longer to be completed. This is to a point where we had to increase time out settings, indexing database more regularly. The MVC project also uses Doctrine ORM. After doing some research, I’m considering using the Symfony Messenger component to process report generation requests asynchronously. It happens to have support of using Doctrine to store the messages, which I think should be able to work well with the Doctrine ORM.

I’d like to know if any one has succeeded in using this Symfony Messenger component with Laminas MVC.

I have also thought of the option of triggering events but I’m not familiar with the mechanism behind EventManager to know whether Events will be processed truly in async fashion (in separate threads/process by the web server (php-fpm).

Laminas EventManager is for syncronous application events, so it is not a direct solution for offloading tasks onto background workers.

Symfony messenger is a good tool for implementing background processing of tasks and I suggest reading its docs thoroughly along with some of the ‘Symfony casts’ tutorials on the subject.

It works absolutely fine with Doctrine DBAL as a transport. Personally, I don’t tend to use a DB as a transport though - for small projects, I tend to use Redis, but prefer to use a DB backend for the failure transport.

Getting all the moving parts wired up in a non-symfony application is perfectly possible but doing it from scratch means writing a fair amount of factories for the various components - you can check out this library and possibly use it - I’ve only used it in Mezzio projects which is its main target.

1 Like