<span id="spc7x"></span>

    <th id="spc7x"></th>

    <li id="spc7x"><object id="spc7x"></object></li>
  1. <rp id="spc7x"></rp>
      <th id="spc7x"><pre id="spc7x"></pre></th>

      <button id="spc7x"><acronym id="spc7x"></acronym></button>

      首頁 > 開發 > Php > 正文

      PHP的Popen函數實現RRDTOOL作圖的動態輸出

      2018-10-16 21:08:43
      字體:
      來源:轉載
      供稿:網友
       最近看了一下RRDTOOL如何作圖,語法確實比較繁瑣,但不是太難。命令行下執行的時候,每次都需要輸出成為一個文件。我們希望做一個應用,能夠動態生成圖表,看了看Cacti的實現方法,核心的部分就是使用了popen這個函數,將命令的輸出放到了管道中,然后循環讀取所有的數據,完成后,再以圖片的形式輸出到客戶端。這樣用戶就能夠看到動態的圖片而不需要進行物理的存儲了,下面是我截取的代碼段,供大家參考。

      error_reporting(E_ALL);

      //作圖命令,注意看 graph 后面加了一個連接符
      $command = '/opt/rrdtool/bin/rrdtool graph - --start=-86400 --end=-300 --title=Test --height=400 --width=800 DEF:value1="/home/echo/workspace/misc/tianjin_dpool_web_21_traffic_in_22.rrd":traffic_in:AVERAGE AREA:value1#ff0000 2>&1';

      //測試管道符
      session_write_close();

      //用管道的方式執行命令,并且接收錯誤輸出
      $handle = popen("$command 2>&1", 'r');
      $read = '';
      while (!feof($handle)) {
      $read .= fgets($handle, 4096);
      }
      pclose($handle);
      echo $read;

      // Set the proper headers to allow caching
      $this->request->headers['Content-Type'] = File::mime_by_ext('png');
      $this->request->headers['Content-Length'] = strlen($read);
      $this->request->headers['Last-Modified'] = date('r', time());
      發表評論 共有條評論
      用戶名: 密碼:
      驗證碼: 匿名發表
      精品国产青草久久久久福利

        <span id="spc7x"></span>

        <th id="spc7x"></th>

        <li id="spc7x"><object id="spc7x"></object></li>
      1. <rp id="spc7x"></rp>
          <th id="spc7x"><pre id="spc7x"></pre></th>

          <button id="spc7x"><acronym id="spc7x"></acronym></button>