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.
Xatoo
source share