0

I have a PHP script that waits for AMQP messages. When a message comes in it is processed and after processing is done it will wait for the next message.

The problem is of course that this is blocking. If e.g. an incoming message needs me to contact an external REST API, the processing could take several seconds to complete and all that time it won't be able to process other messages.

I can start my script several times, e.g. 8 times. This way I have 8 "consumers" and this seems to work very well. However, the problem now is, how do I manage these 8 different processes?

I basically looking for some utility that allows me to specify that I want to start a particular script 8 times and then to be able monitors these processes for up time etc. Is there such utility?

Luke
  • 3,826
  • 8
  • 36
  • 40

1 Answers1

3

Use upstart.

Edit /etc/init/whateveryouwant.conf

start on runlevel [2345]

task

env CONSUMERS=8

script
  for i in `seq 1 $CONSUMERS`
  do
    start /fullpath/to/your/script/here CONSUMER=$i
  done
end script
respawn limit 15 5

Then you can use service whateveryouwant start service whateveryouwant stop

Geraint Jones
  • 2,503
  • 16
  • 19