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