我一直使用:
$pid = exec("/usr/local/bin/php file.php $args > /dev/null & echo \$!");
但我正在使用XP虚拟机来开发一个Web应用程序,我不知道如何获得在Windows窗口中的PID。
我试过这个cmd:
C:\\wamp\\bin\\php\\php5.2.9-2\\php.exe "file.php args" > NUL & echo $!
它得到的文件执行,但输出是“$!”
我怎样才能得到进入var $ pid的pid? (使用php)
你将不得不安装一个额外的扩展 ,但找到解决方案位于Uniformserver的维基 。
UPDATE
经过一番搜索后,你可能会看到tasklist
,你可能可以使用PHP的exec
命令来得到你在做什么。
我正在使用Pstools ,它允许你在后台创建一个进程并捕获它的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];
这是一个有点哈克,但它完成了工作