Dynamic output of RRDTOOL drawing using PHP Popen _ PHP Tutorial

Source: Internet
Author: User
Tags rrdtool
Use Popen of PHP to achieve dynamic output of RRDTOOL plotting. A closer look at how RRDTOOL is structured. The syntax is indeed cumbersome, but not too difficult. Each time the command line is executed, it must be output as a file. We hope to make an application. we will take a closer look at how RRDTOOL is structured. The syntax is indeed cumbersome, but not too difficult. Each time the command line is executed, it must be output as a file. We hope to make an application to dynamically generate charts and look at the Cacti implementation method. The core part is to use the popen function to output commands to the pipeline, then read all the data cyclically, and then output it to the client as an image. In this way, you can see dynamic images without the need for physical storage. The following is the code segment I have captured for your reference.

Error_reporting (E_ALL );

// Drawing command. Note that a connector is added 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 the channel operator
Session_write_close ();

// Execute commands in MPs queue mode and receive 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

Bytes. Each time the command line is executed, it must be output as a file. We hope to make an application ,...

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.