Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't rrdtool generate any PNG output in my Perl CGI program?
    primarykey
    data
    text
    <p>I'm trying to output an image from RRD Tool using Perl. I've posted the relevant part of the CGI script below:</p> <pre><code>sub graph { my $rrd_path = $co-&gt;param('rrd_path'); my $RRD_DIR = "../data/"; #generate a PNG from the RRD my $png_filename = "-"; # a '-' as the filename send the PNG to stdout my $rrd = "$RRD_DIR/$rrd_path"; my $png = `rrdtool graph $png_filename -a PNG -r -l 0 --base 1024 --start -151200 -- vertical-label 'bits per second' --width 500 --height 200 DEF:bytesInPerSec=$rrd:bytesInPerSec:AVERAGE DEF:bytesOutPerSec=$rrd:bytesOutPerSec:AVERAGE CDEF:sbytesInPerSec=bytesInPerSec,8,* CDEF:sbytesOutPerSec=bytesOutPerSec,8,* AREA:sbytesInPerSec#00cf00:AvgIn LINE1:sbytesOutPerSec#002a97:AvgOut VRULE:1246428000#ff0000:`; #print the image header use bytes; print $co-&gt;header(-type=&gt;"image/png",-Content_length=&gt;length($png)); binmode STDOUT; print $png; }#end graph </code></pre> <p>This works fine on the command line (perl graph.cgi > test.png) - commenting out the header, of course, as well as on my Ubuntu 10.04 development machine. However, when I move to the Centos 5 production server, it doesn't, and the browser receives a content-length of 0:</p> <p>Ubuntu 10.04/Apache:</p> <pre><code>Request URL:http://noc-student.nmsu.edu/grasshopper/web/graph.cgi Request Method:GET Status Code:200 OK Request Headers Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Cache-Control:max-age=0 User-Agent:Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.36 Safari/534.7 Response Headers Connection:Keep-Alive Content-Type:image/png Content-length:12319 Date:Fri, 08 Oct 2010 21:40:05 GMT Keep-Alive:timeout=15, max=97 Server:Apache/2.2.14 (Ubuntu) </code></pre> <p>And from the Centos 5/Apache Server:</p> <pre><code>Request URL:http://grasshopper-new.nmsu.edu/grasshopper/branches/michael_dev/web/graph.cgi Request Method:GET Status Code:200 OK Request Headers Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Cache-Control:max-age=0 User-Agent:Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.36 Safari/534.7 Response Headers Connection:close Content-Type:image/png Content-length:0 Date:Fri, 08 Oct 2010 21:40:32 GMT Server:Apache/2.2.3 (CentOS) </code></pre> <p>The <code>use bytes</code> and manual setting of the content length are in there to try to fix the problem, but it's the same without them. Same with setting <code>binmode</code> on STDOUT. The script works fine from the command line on both machines.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload