Good afternoon, I came across a problem: you need to create several php-workers who will listen to the RabbitMQ queue server.
Googled 4 options for implementing the task:
- Cron with a preliminary check for the existence of workers.
- Sh-script with an infinite loop (+ startup in the OS) with the same (as above) check for the existence of the worker, and launch if necessary.
I liked the last option more, because It is not solved with crutches (in my opinion), and with regular Linux tools, and you do not need to install third-party software.
Please tell me how this is the right decision? What are the cons or pros of this solution?
Here is the algorithm of my actions:
creating the file /etc/systemd/system/php-queue-worker@.service
With this content:
[Unit] Description=PHP QUEUE WORKER %I After=network.target [Service] User=root Group=root ExecStart=/usr/bin/php /var/www/html/worker.php Restart=always [Install] WantedBy=multi-user.target
Add systemctl enable php-queue-worker @ 1 to startup
Problems that have not yet been resolved: how to automatically launch several workers. For example, to always be 5? Perhaps also help solve this problem. I will be grateful.