jeteve has asked for the wisdom of the Perl Monks concerning the following question:

Hello wise monks. I've got problem using GraphViz within apache. In command line mode, this module works pretty well and I'm really happy with it. But as a cgi within apache, it's seems impossible to make it generate anything else than a 0 sized file :(

Found a solution!! : GraphViz needs a HOME environment variable. A SetEnv HOME /tmp/ (for instance) in apache conf fixed the problem. Actually it was written in the GraphViz FAQ about the same problem under debian.

Therefore, I deeply apologize for the time you worried about this problem.

My conf: GraphViz 2.02 uname -a Linux -- 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/L +inux Apache/2.0.40 perl v5.8.0 built for i386-linux-thread-multi Here is my CGI: #! /usr/bin/perl -w use GraphViz; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); my $g = GraphViz->new( directed => 0 ); my $europe = { name =>'Europe', style =>'filled', fillcolor =>'lightgray', fontname =>'arial', fontsize =>'12' }; $g->add_node('London' , shape => 'hexagon' , URL => 'http://www.eteve. +net/', cluster=> $europe ); $g->add_node('Paris', cluster => $europe ); $g->add_node('New York'); $g->add_node('LA', label => '' , style => 'invis' , height => 0 , width => 0 , shape => 'circle' , ); $g->add_node('Amsterdam', cluster => $europe); $g->add_edge('London' => 'Paris'); $g->add_edge('London' => 'New York', label => 'Far'); $g->add_edge('Paris' => 'LA' , label => 'Very far'); $g->add_edge('LA', 'New York', label => 'Not so far'); $g->add_edge('Paris' => 'London' ,minlen => 0 , weight => 100 ); open IMG , ">/tmp/img.jpg"; binmode IMG ; print IMG $g->as_jpeg; close IMG ;
The problem is the image /tmp/img/jpeg is zero sized. When the GraphViz code is ran from the command line, it works perfectly.

-- Nice photos of naked perl sources here !

Replies are listed 'Best First'.
Re: GraphViz , apache
by merlyn (Sage) on Aug 16, 2005 at 16:05 UTC
    You didn't check your return status on the open. Also, you didn't say you looked at the error log, finding nothing there. Fix both of those, and that might also fix your problem.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      The file was created, so the open appear to have succeeded. If that's the case, check the error returned by print and by close. It's possible the user has a quota on that drive and has already used it up.
        The file was created, so the open appear to have succeeded.
        It's not clear in the original posting that this might not be an empty file in the way of the actual creation. Adding an "or die" here would be useful to rule that out.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

      I've check all off these, without any further indication :(

      -- Nice photos of naked perl sources here !

Re: GraphViz , apache
by Anonymous Monk on Aug 18, 2005 at 05:55 UTC
    I have faced similar problems in the past. For me, the cgi version didn't have access to the image library such as libpng.so or libjpeg.so etc. That produced zero byte sized image files.
      That sounds good to me! Do you remember how did yo fix that ? J.

      -- Nice photos of naked perl sources here !

        I just forced the LD_LIBRARY_PATH environment variable to the right path while starting up the CGI script. Its hacky, but worked for me.
Re: GraphViz , apache
by jeteve (Pilgrim) on Aug 21, 2006 at 14:29 UTC
    I fixed this problem by added a HOME environment variable (setted to tmp) within the graphviz running directory. Graphviz requires a HOME to work properly.

    -- Nice photos of naked perl sources here !