[rrd-users] Re: rrdgraph cgi script fails under mod_perl: UPDATE

Nick Sharp njsharp at bigpond.net.au
Fri Feb 24 01:57:52 MET 2006

Thanks Chris. I found this:

"6.4.4. STDIN, STDOUT, and STDERR Streams
Under mod_perl, both STDIN and STDOUT are tied to the socket from which the request originated."
"6.4.5. Redirecting STDOUT into a Scalar Variable
Sometimes you encounter a black-box function that prints its output to the default file handle 
(usually STDOUT) when you would rather put the output into a scalar. This is very relevant under 
mod_perl, where STDOUT is tied to the Apache request object. In this situation, the IO::String 
package is especially useful. You can re-tie( ) STDOUT (or any other file handle) to a string by 
doing a simple select( ) on the IO::String object. Call select( ) again at the end on the original 
file handle to re-tie( ) STDOUT back to its original stream:

     my $str;
     my $str_fh = IO::String->new($str);

     my $old_fh = select($str_fh);
     black_box_print( );
     select($old_fh) if defined $old_fh;

In this example, a new IO::String object is created. The object is then selected, the 
black_box_print( ) function is called, and its output goes into the string object. Finally, we 
restore the original file handle, by re-select( ) ing the originally selected file handle. The $str 
variable contains all the output produced by the black_box_print( ) function."
That looked like just what I needed:
For "black_box_print();" use "RRDs::graph (etc);".
And at the end "print $str"

Sadly, the alleged redirection does not seem to be happening, libpng still gives the error, and I 
have no graph (:-((

Is that good code?  It looks a bit strange to me, but hey what do I know?

Should that all work under mod_perl?

TOBIAS: Would it be possible to add a third option for RRDs::graph output destination

1	filename
2	- (=STDOUT)
3	$xxx (a predefined variable, presumably global)<<<<<<<<<<

or is there a known good way to redirect "-" output to a scalar variable?

Regards, and advance apologies for any newbie sillies!
Nick Sharp
MA Hons (Oxon), MBCS, CITP
International ICT Infrastructure Consultant
eMl:	njsharp at bigpond.net.au
Add:	77 Brighton Street
	NSW 2096
Tel:	+61 2 9938 3459
Mob:	+61 413 948 375

"Human history becomes more and more a race between education and catastrophe."
[H G Wells: The Outline of History (1920)]

Chris Wilson wrote:
> Hi Nick,
> On Thu, 2006-02-23 at 18:32 +1100, Nick Sharp wrote:
>> It still fails to generate the graph, and the httpd error log
>> EVENTUALLY still shows:
>> libpng error: write error
>> but only, as before, after the httpd has been stopped.
> With mod_perl, STDOUT does not necessarily go to the browser. It's
> better to use the perl "print" function, which at least with the old
> mod_perl under apache 1, was overridden by mod_perl to go somewhere
> useful (i.e. to the browser).
> Can you get RRDs::graph to return the image data in a variable that you
> can print, instead of sending it directly to STDOUT?
> Cheers, Chris.

Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://lists.ee.ethz.ch/rrd-users
WebAdmin    http://lists.ee.ethz.ch/lsg2.cgi

More information about the rrd-users mailing list