Categories
PHP

Solution: Symfony message handler doesn’t complete

If your Symfony Messenger message handler doesn’t finish executing it is mostly due to an error or a memory shortage. Also make sure your routing is set up correctly.

So, check your logs for errors. If there are no errors to be solved your program probably doesn’t have enough memory to finish the task at hand. Check that your consumer has enough memory to execute the task you are trying to complete.

To do this simply set the required memory per consumer via the –memory-limit option. You can do this in your supervisor programs config.

Example config using the geerlingguy.supervisor role in ansible:

supervisor_programs:
 - name: 'consumer-async'
   command: 'php /path/to/your/app/bin/console messenger:consume --memory-limit=1024M --limit=10 async'
   state: present
   configuration: |
     numprocs=1
     startsecs=0
     autostart=true
     autorestart=true
     process_name=%(program_name)s_%(process_num)02d

As you can see we also use the limit option. In this example this option tells Symfony to kill the process after handling 10 messages. This is done to avoid a package (like Doctrine) from accumulating memory over time. When the process is killed supervisor will automatically start a new program that again will accept 10 messages.

If you manage supervisor manually, copy and adjust this code:

;/etc/supervisor/conf.d/messenger-worker.conf
[program:messenger-consume]
command=php /path/to/your/app/bin/console messenger:consume --memory-limit=1024M --limit=10 async
numprocs=1
startsecs=0
autostart=true
autorestart=true
process_name=%(program_name)s_%(process_num)02d

Leave a Reply

Your email address will not be published. Required fields are marked *