How to get PID from PHP function exec() in Windows?

后端 未结 4 710
离开以前
离开以前 2021-02-08 16:53

I have always used:

$pid = exec(\"/usr/local/bin/php file.php $args > /dev/null & echo \\$!\");

But I am using an XP virtual machine to

4条回答
  •  野性不改
    2021-02-08 17:13

    Here's a somewhat less "hacky" version of SeanDowney's answer.

    PsExec returns the PID of the spawned process as its integer exit code. So all you need is this:

    &1', $output, $pid);
          return $pid;
        } // spawn
    
        echo spawn('phpinfo.php');
    
    ?>
    

    The -accepteula argument is needed only the first time you run PsExec, but if you're distributing your program, each user will be running it for the first time, and it doesn't hurt anything to leave it in for each subsequent execution.

    PSTools is a quick and easy install (just unzip PSTools somewhere and add its folder to your path), so there's no good reason not to use this method.

提交回复
热议问题