zoukankan      html  css  js  c++  java
  • Xhprof graphviz Warning: proc_open() [function.proc-open]: CreateProcess failed, error code 解决方法

    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'
    ";
          exit;
        }
    
        fclose($pipes[2]);
        fclose($pipes[1]);
        proc_close($process);
        return $output;
      }
      print "failed to execute cmd "$cmd"";
      exit();
    

      

    }

  • 相关阅读:
    python基础之函数(基础七)
    python基础之文件操作(基础六)
    python基础之数据类型补充(基础五)
    python之深浅拷贝(基础四)
    python基础数据类型之字典(基础三)
    python基础数据类型之列表,元组(基础二)
    python基础入门二
    随笔
    oss 上传照片失败
    mysql 同表查询更新
  • 原文地址:https://www.cnblogs.com/wuxiang12580/p/10346847.html
Copyright © 2011-2022 走看看