如何获取proc_open()执行的进程的内存使用情况

时间:2012-12-30 13:57:18

标签: php windows

我必须测量proc_open()执行的进程的内存使用和执行时间。测量时间并不难,但我找不到任何方法来获取内存使用情况。 (程序可以很快终止)

是否有任何方法可以获取proc_open()执行的进程的内存使用情况?

出于某种原因,我的操作系统是Windows。

1 个答案:

答案 0 :(得分:1)

@ love-paper,利用proc_open的descriptorspec参数将内存使用量写入文件,然后可以读入。

父进程

$child_id = uniqid();
$descriptorspec = array(
   2 => array("file", "/tmp/$child_id", "a") // stderr is a file to write to
);
proc_open($cmd, $descriptorspec);

$memory_used = file_get_contents("/tmp/$child_id");

子进程

// at the end of the script
file_put_contents('php://stderr', memory_get_peak_usage(true));