Use php to call graphviz to draw a topology

Source: Internet
Author: User
Using php to call graphviz to easily draw a topology graph graphviz is an ancient tool for drawing a Topology Graph. it is very powerful and can be converted to a topology graph according to the format defined in your text file, many large companies use graphviz to draw topology diagrams. The main function of graphviz is to use a program to generate text and then call graphviz to convert the text into a topology graph. 1. install graphviz to www. graphviz. orgDow. use php to call graphviz to easily draw a topology.
Graphviz is an ancient tool for drawing topology graphs. it is very powerful and can be converted to a topology graph according to the format defined in your text file, many large companies use graphviz to draw topology diagrams. The main function of graphviz is to use a program to generate text and then call graphviz to convert the text into a topology graph.
1. install graphviz
Download the corresponding platform installation package at http://www.graphviz.org/download..php;
I use centos, so yum is the most convenient for installation.



Wget http://www.graphviz.org/graphviz-rhel.repo/etc/yum. repos. d/graphviz-rhel.repo
Yum install graphviz





2. perform a test after installation.



Echo "digraph G {Hello-> World}" | dot-Tpng> hello.png





3. php calls graphviz

First, use the program to generate/tmp/domain.txt, and then use the dot command to generate an image.



Header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past

Header ("Last-Modified:". gmdate ("D, d m y h: I: s"). "GMT"); // always modified

Header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1

Header ("Pragma: no-cache"); // HTTP/1.0

Header ("Content-type: image/gif ");
$ Filename = '/tmp/domain.txt ';
$ Somecontent = "digraph G {a-> B-> c-> }";
If (! $ Handle = fopen ($ filename, 'w ')){
Echo "cannot open $ filename ";
Exit;
}
If (fwrite ($ handle, $ somecontent) === FALSE ){
Echo "cannot write to $ filename ";
Exit;
}
Fclose ($ handle );

Passthru ("dot-Tpng $ filename ");
// Passthru ("cat $ filename | dot-Tpng ");

?>

End

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.