PHP Daemon/worker environment

后端 未结 5 692
一个人的身影
一个人的身影 2020-12-07 16:02

Problem: I want to implement several php-worker processes who are listening on a MQ-server queue for asynchronous jobs. The problem now is that simply running this processes

5条回答
  •  粉色の甜心
    2020-12-07 16:42

    It sounds like you already have a MQ up and running on a *nix system and just want a way to manage workers.

    A very simple way to do so is to use GNU screen. To start 10 workers you can use:

    #!/bin/sh
    for x in `seq 1 10` ; do
    screen -dmS worker_$x php /path/to/script.php worker$x
    end
    

    This will start 10 workers in the background using screens named worker_1,2,3 and so on.

    You can reattach to the screens by running screen -r worker_ and list the running workers by using screen -list.

    For more info this guide may be of help: http://www.kuro5hin.org/story/2004/3/9/16838/14935

    Also try:

    • screen --help
    • man screen
    • or google.

    For production servers I would normally recommend using the normal system startup scripts, but I have been running screen commands from the startup scripts for years with no problems.

提交回复
热议问题