Xhprof在windows下點擊[View Full Callgraph]調用graphviz軟件時。
警告Warning: proc_open() [function.proc-open]: CreateProcess failed, error code – 0 in
並提示
failed to execute cmd " D:/graphviz-2.38/release/bin/dot -Tpng"
位置是xhprof_lib/utils/callgraph_utils.php文件下xhprof_generate_image_by_dot函數
windows下
$cmd = " dot -T".$type;
需要替換成
$cmd = " D:/graphviz-2.38/release/bin/dot -T".$type;
問題就出現在這行代碼
$process = proc_open($cmd, $descriptorspec, $pipes, "/tmp", array());
需要改成
$process = proc_open($cmd, $descriptorspec, $pipes);
或者是建立相應的tmp文件夾,因為默認是不存在tmp文件夾的。嘗試在網站根目錄建立tmp文件夾但是還是保存,於是改成了在當前目錄。
$process = proc_open($cmd, $descriptorspec, $pipes, "tmp", array());
//修改后的正確代碼
function xhprof_generate_image_by_dot($dot_script, $type) {
//echo($dot_script);
$descriptorspec = array(
// stdin is a pipe that the child will read from
0 => array("pipe", "r"),
// stdout is a pipe that the child will write to
1 => array("pipe", "w"),
// stderr is a pipe that the child will write to
2 => array("pipe", "w")
);
//$cmd = " dot -T".$type; //linux下
//1.修改graphviz目錄
$cmd = " D:/graphviz-2.38/release/bin/dot -T".$type;//windows下
//2.tmp文件夾處理
$process = proc_open($cmd, $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $dot_script);
fclose($pipes[0]);
$output = stream_get_contents($pipes[1]);
$err = stream_get_contents($pipes[2]);
if (!empty($err)) {
print "failed to execute cmd: \"$cmd\". stderr: `$err'\n";
exit;
}
fclose($pipes[2]);
fclose($pipes[1]);
proc_close($process);
return $output;
}
print "failed to execute cmd \"$cmd\"";
exit();
}
