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, ...