Symfony: should I add the rabbitmq:consumer command to crontab? Symfony: should I add the rabbitmq:consumer command to crontab? symfony symfony

Symfony: should I add the rabbitmq:consumer command to crontab?


The more accepted method is to keep your consumer running. There are tools like Supervisor and Circus that can help you with that. See this discussion. But if you can get your consumer to exit when there are no more messages, you could also use cron. Although this might cause a delay in consuming the messages. You can't react on messages instantly. Users might have to wait a minute before any task is started / mail is received.

Please take the following into account when running your consumer (or any PHP code for that matter) for a long time:

Try to avoid memory usage accumulation. Don't keep appending to arrays without ever clearing them. This means for instance that you shouldn't use FingersCrossedHandler in Monolog since this keeps a buffer of log messages. Fine for a single request, not for a daysworth of debug messages.

Even when you are careful, PHP might leak memory. What can you say, PHP... (That could indeed be a catchphrase) In my situation I have a cronjob installed that restarts the workers every night, but in theory the consumers could run about a month before they run out of memory.