Asynchronous shell exec in PHP

前端 未结 13 2165

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

    On linux you can do the following:

    $cmd = 'nohup nice -n 10 php -f php/file.php > log/file.log & printf "%u" $!';
    $pid = shell_exec($cmd);
    

    This will execute the command at the command prompty and then just return the PID, which you can check for > 0 to ensure it worked.

    This question is similar: Does PHP have threading?

提交回复
热议问题