Asynchronous shell exec in PHP

前端 未结 13 2188

I\'ve got a PHP script that needs to invoke a shell script but doesn\'t care at all about the output. The shell script makes a number of SOAP calls and is slow to complete,

13条回答
  •  执笔经年
    2020-11-22 01:16

    Use a named fifo.

    #!/bin/sh
    mkfifo trigger
    while true; do
        read < trigger
        long_running_task
    done
    

    Then whenever you want to start the long running task, simply write a newline (nonblocking to the trigger file.

    As long as your input is smaller than PIPE_BUF and it's a single write() operation, you can write arguments into the fifo and have them show up as $REPLY in the script.

提交回复
热议问题