Skip to content

Symfony 7: Messenger

Send messages (async) - development

ddev sc messenger:consume async -vv

Send messages (async) using systemd - production

# verify (expect: no error)
systemctl --user show-environment

# create directory if not exist
mkdir -p ~/.config/systemd/user

# create systemd service
vim ~/.config/systemd/user/symfony-messenger-worker@.service
[Unit]
Description=Symfony messenger-consume %i

[Service]
ExecStart=php /home/webhook/domains/webhook.parcelvalue.eu/website/bin/console messenger:consume async --time-limit=3600
# for Redis, set a custom consumer name for each instance
Environment="MESSENGER_CONSUMER_NAME=symfony-%n-%i"
Restart=always
RestartSec=30

[Install]
WantedBy=default.target
systemctl --user daemon-reload
# enable
systemctl --user enable symfony-messenger-worker@1.service
# start
systemctl --user start symfony-messenger-worker@1.service
# status
systemctl --user status symfony-messenger-worker@1.service
# if changing service file
systemctl --user daemon-reload
# restart all
# note, this seems to be faster than `php bin/console messenger:stop-workers` which is in the official docs
systemctl --user restart symfony-messenger-worker@*.service
# start at boot instead of at login
loginctl enable-linger webhook
# verify
loginctl show-user webhook -p Linger

Troubleshooting

  • sudo or root
# specific service
journalctl -f --user-unit messenger-consume@1.service

# all services
journalctl -f --user-unit symfony-messenger-worker@*

# all services for user
journalctl -f _UID=$UID