Answer the question
In order to leave comments, you need to log in
How to control the life of php consumers?
We often have to work with queue systems in php.
To develop a script that will listen to a specific queue (consumer), we simply create a script that listens to this queue in an infinite loop.
The script itself is daemonized - run via supervisor, or systemd.
If for some reason the script crashes, the system restarts.
Questions:
1. I often hear from other developers or articles that php is not meant to last.
They criticize such decisions as ours, because they are not reliable.
How then do they solve such problems?
And how is it generally accepted to solve such problems?
Can you recommend reading articles or some case studies?
2. I understand that there may be cases when the script hangs, and as a result, the consumer itself does not work, but it does not crash, so that the system restarts. What are the solutions in these cases? What can cause the script to rotate?
I thought there are two states: working and not (completed successfully or with an error).
And how do others decide?
Such a decision comes to my mind:
Each consumer is periodically obliged to submit signs of life - to record the date and time of activity in a certain database table.
And by cron, another script checks the records in the table, if some consumer has not updated the record for a long time - kill the process by pid.
Answer the question
In order to leave comments, you need to log in
1. Bad developers say so.
But it depends on the amount of logic in the workers. If there is a lot of it, then PHP is a good choice.
If it is not enough, but often - it is better to look towards go, for example.
2. Monitor the status of queues.
Each consumer is periodically obliged to submit signs of life - to record the date and time of activity in a certain database table.
And how do others decide?
Such a decision comes to my mind:
Each consumer is periodically obliged to submit signs of life - to record the date and time of activity in a certain database table.
And by cron, another script checks the records in the table, if some consumer has not updated the record for a long time - kill the process by pid.
[Service]
...
WatchdogSec=30s
Restart=on-failure
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question