Asynchronous shell exec in PHP

前端 未结 13 1983

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

    I used this...

    /** 
     * Asynchronously execute/include a PHP file. Does not record the output of the file anywhere.  
     * Relies on the PHP_PATH config constant.
     *
     * @param string $filename  file to execute
     * @param string $options   (optional) arguments to pass to file via the command line
     */ 
    function asyncInclude($filename, $options = '') {
        exec(PHP_PATH . " -f {$filename} {$options} >> /dev/null &");
    }
    

    (where PHP_PATH is a const defined like define('PHP_PATH', '/opt/bin/php5') or similar)

    It passes in arguments via the command line. To read them in PHP, see argv.

提交回复
热议问题