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

I have read many (large) articles on integrating RabbitMQ into a Symfony application.

RabbitMqBundle makes it easy to settle, and it provides a convenient rabbitmq:consumer command to consume messages from the queue as follows:

 app/console rabbitmq:consumer -m 50 upload_picture 

I have a question. If you recommend adding this command to crontab? Are there any recommendations on this?

+7
symfony rabbitmq
source share
1 answer

A more acceptable method is to keep your consumer running. There are tools like Supervisor and Circus that can help you with this. See this discussion . But if you can get your consumer to exit when there are no more messages, you can also use cron. Although this may cause a delay in the use of messages. You cannot immediately respond to messages. Users may need to wait a minute before starting any task or receiving mail.

Bear in mind that when you run your consumer (or any other PHP code) for a long time:

Try to avoid accumulating memory. Do not add to arrays without cleaning them. This means, for example, that you should not use the FingersCrossedHandler in Monolog, since this saves the log message buffer. Perfect for a single request, not for daytime debugging messages.

Even when you are careful, PHP may skip memory. What can you say, PHP ... (It really can be a phrase). In my situation, I have a cronjob installed that restarts workers every night, but theoretically consumers can work for about a month before they run out of memory.

+6
source share

All Articles