Asynchronous shell exec in PHP

前端 未结 13 2031

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:14

    If it "doesn't care about the output", couldn't the exec to the script be called with the & to background the process?

    EDIT - incorporating what @AdamTheHut commented to this post, you can add this to a call to exec:

    " > /dev/null 2>/dev/null &"
    

    That will redirect both stdio (first >) and stderr (2>) to /dev/null and run in the background.

    There are other ways to do the same thing, but this is the simplest to read.


    An alternative to the above double-redirect:

    " &> /dev/null &"
    

提交回复
热议问题