Using PHP to call Graphviz light drawing topology diagram

Source: Internet
Author: User
Easily draw a topology diagram with PHP call Graphviz
Graphviz is an ancient painting topology of the tool, very powerful, in accordance with the format you define in the text file into a topology map, many large companies are using Graphviz to draw topology diagram, its main function is to use the program to generate text, Then call Graphviz to convert the text into a topology diagram.
1. Installing Graphviz
Download the installation package for the corresponding platform in the http://www.graphviz.org/Download..php;
I'm using CentOS so it's easy to install with Yum



wget Http://www.graphviz.org/graphviz-rhel.repo/etc/yum.repos.d/graphviz-rhel.repo
Yum Install Graphviz





2. Test after the installation is complete



echo "digraph G {Hello->world}" | Dot-tpng >hello.png





3.php Call Graphviz

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



Header ("Expires:mon, 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->a}";
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
  • 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.