Using PHP's popen to realize dynamic output of RRDtool drawing _php Tutorial

Source: Internet
Author: User
Tags rrdtool
Look at a little bit rrdtool how to draw, grammar is really cumbersome, but not too difficult. When executed at the command line, the output is required to be a file each time. We want to do an application, be able to dynamically generate charts, look at the implementation of cacti, the core part is the use of popen this function, the output of the command is placed in the pipeline, and then iterate through all the data, after completion, and then output to the client in the form of a picture. So that users can see the dynamic picture without the need for physical storage, the following is the code snippet I intercepted for your reference.

Error_reporting (E_all);

Draw a command, notice that a connector is appended to the 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 ';

Test pipe break
Session_write_close ();

Executes the command in a pipeline and receives an error output
$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 ());

From:lonely Blog

http://www.bkjia.com/PHPjc/478707.html www.bkjia.com true http://www.bkjia.com/PHPjc/478707.html techarticle look at a little bit rrdtool how to draw, grammar is really cumbersome, but not too difficult. When executed at the command line, the output is required to be a file each time. We want to do an application, ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.