0

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:

  1. Cron with a preliminary check for the existence of workers.
  2. 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.
  3. Supervisor
  4. Systemd

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.