4

我在 Windows apache 服务器的后台启动了一个进程。

index.php 如下:

<?php
$cmd = "C:/xampp/php/php.exe -f test.php";
pclose(popen("start /B ". $cmd, "r"));
echo "OK";
?>

test.php 如下:

<?php
sleep(5);
file_put_contents("1.txt", date("Y-m-d H:i:s"));
?>

当时,我想得到 pid which php -f test.php。当我启动 index.php 时,我可以在命令行的输出中看到新php.exe进程。tasklist我怎样才能得到这个后台进程的pid。

谢谢。

4

1 回答 1

2

这将ProcessID使用 执行任务后输出wmic。然后,您可以将其存储在会话或 cookie 中以在页面之间传递。

$cmd = 'wmic process call create "C:/xampp/php/php.exe -f /path/to/htdocs/test.php" | find "ProcessId"';

$handle = popen("start /B ". $cmd, "r");

$read = fread($handle, 200); //Read the output 

echo $read; //Store the info 

pclose($handle); //Close

输出

ProcessId = 1000
于 2016-11-21T10:33:10.800 回答