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

后端 未结 4 779
离开以前
离开以前 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:19

    I'm using Pstools which allows you to create a process in the background and capture it's pid:

    // use psexec to start in background, pipe stderr to stdout to capture pid
    exec("psexec -d $command 2>&1", $output);
    // capture pid on the 6th line
    preg_match('/ID (\d+)/', $output[5], $matches);
    $pid = $matches[1];
    

    It's a little hacky, but it gets the job done

提交回复
热议问题