[Mapserver-users] Sending image to stdout under Apache

Lowell Filak lfilak at medinaco.org
Thu Mar 6 10:17:04 EST 2003


In an attempt to sum this thread up (hopefully correctly, but open for
corrections):
If using mod_perl you can't send the image binary to STDOUT because the
binary can reach the browser before the content-type does or does not
reach it at all because the content-type is sent to the browser via
'print "..."' and print is guaranteed to make it but the C STDOUT is
not directly tied to the socket the client request came in on so STDOUT
is not guaranteed to make it.
If using the Perl script as a cgi then the '$img->saveImage...' should
work because STDOUT for that process is directly tied to the client
connection.
The OUT descriptor I found was a mistake on my part.
OUT is actually part of embperl - more on this in a minute.
By using OUT or JUNK or any descriptor name in a print statement that is 
not declared will automatically print to STDOUT - Perl is based around
language, ie. "You right what u think you want it to due & ..." - that
is why the test I ran outside of mod_perl worked.
Back to OUT & gd.pm:
As Eric pointed out some modules contain a way to assure that a method
call intended for STDOUT is sent to the same place as a 'print' to
STDOUT even under mod_perl.
Jason proposed taking a look at setting something such as this up for
mapscript.pm, which as I understand it requires mapscript.pm create a
filehandle (such as OUT) and tie it to STDOUT itself without relying on
mod_perl to do it.
Clear as mud.?
At this point it appears it would be a good thing to
have if the developer(s) approve(s) (Steve, thoughts?).
Lowell F.

The following message was sent by Joe Bussell <joe at otsys.com> on Wed, 05 Mar 2003 15:51:10 -0800.

> I like the idea, but I have not been able to reproduce your results.  I 
> currently produce maps for TrafficDodger using the two-step temp file 
> technique.  I would like to rip the image right to Apache.  The 
> filehandle OUT is not defined in my system.  I wonder what you have set, 
> or exported to get this to produce useful results.  Have you declared an 
> output file?
> 
> If I write to STDOUT I get complaints  "Use of uninitialized value in 
> null operation".  It appears that $img->saveImage( undef, 
> $mapscript::MS_PNG, 1, 1, 95 ); is not returning anything useful for the 
> print call.  Any ideas?
> 
> Is this dependent on the latest rev of Mapserver?
> 
> Cordially,
> 
> Joe Bussell
> 
> 
> Lowell Filak wrote:
> > Doh!
> > That's what I get for being in a hurry.
> > From what I've read:
> > 1) You don't need binmode on *n*x.
> > 2) You need to print to OUT as opposed to STDOUT or the content is shipped before the content-type.
> > print OUT $ref_img->saveImage(undef, $mapscript::MS_PNG, $map->{transparent}, $map->{interlace}, 0);
> > HTH
> > Lowell F.
> > 
> > The following message was sent by Eric Bridger <eric at gomoos.org> on 05 Mar 2003 10:57:23 +0000.
> > 
> > 
> >>Thanks Lowell,
> >>
> >>Yes, that was the work-around I mentioned.  But avoiding the write to
> >>disk is what I am after.  I have found that using /cgi-bin/mapserv as an
> >>image engine results in significant performance improvements for our
> >>mapscript application.  But constructing the proper query strings to
> >>manipulate the map is cumbersome and seems to have certain limitations. 
> >>I'd prefer to manipulate the map using mapscript and then print it to
> >>the stdout. But somehow, using $img->saveImage(undef, ...) which spends
> >>some time doing something, never sends the image to the stdout when run
> >>as a CGI.  From the command line, it works.
> >>
> >>We don't have this problem with a graphing application in the same
> >>environment which uses GD.pm.
> >>
> >>
> >>On Wed, 2003-03-05 at 15:27, Lowell Filak wrote:
> >>
> >>>Hmmm...
> >>>I thought I replied back concerning that.?
> >>>Just do a:
> >>>print "Content-type: image/png\n\n";
> >>>system("cat junk.png");
> >>>and that will send the image to stdout/the browser.
> >>>HTH
> >>>Lowell F.
> >>>
> >>>The following message was sent by Eric Bridger <eric at gomoos.org> on 05 Mar 2003 08:59:12 +0000.
> >>>
> >>>
> >>>>
> >>>>The list archives show that this came up last Dec.
> >>>>(http://mapserver.gis.umn.edu/data2/wilma/mapserver-users/0212/msg00265.html) and while a work around was suggested there was no solution to the problem given, so I was wondering if anyone else had run into this problem. 
> >>>>
> >>>>I'm having a problem using Perl mapscript $img->saveImage(undef, ...),
> >>>>to send an image, PNG and/or JPEG, to the standard output under Apache. 
> >>>>Running in /cgi-bin I have the following script: 
> >>>>
> >>>>my $map = new mapscript::mapObj($ms_dir . "/test.map"); 
> >>>>
> >>>>my $ref_img = $map->drawReferenceMap(); 
> >>>>
> >>>># This works fine: 
> >>>>#$ref_img->saveImage("junk.png", $mapscript::MS_PNG,  
> >>>>$map->{transparent}, $map->{interlace}, 0); 
> >>>>
> >>>>print "HTTP/1.0 200 OK\n"; 
> >>>>print "Content-type: image/png\r\n\r\n"; 
> >>>>binmode STDOUT; 
> >>>>
> >>>># this produces no output on Apache's STDOUT 
> >>>>$ref_img->saveImage("", $mapscript::MS_PNG, $map->{transparent},
> >>>>$map->{interlace}, 0); 
> >>>>
> >>>>$ref_img->free(); 
> >>>>exit; 
> >>>>
> >>>>
> >>>>>From the command line this script works as expected.  But when run under
> >>>>Apache/mod_perl  it's as if the C msSaveImage() stdout stream is
> >>>>pointing somewhere other than the Apache stdout (i.e. the client
> >>>>browser). 
> >>>>
> >>>>The work around of course is to save a disk file and then print it, but
> >>>>the whole point of this is to avoid the temp. disk files.  I've noticed
> >>>>a significant increase in performance when using mapserv as an image
> >>>>engine rather then using temp disk files. 
> >>>>
> >>>>Thanks. 
> >>>>Eric 
> >>>>
> >>>>
> >>>>Setup: 
> >>>>
> >>>>Apache/1.3.26 (Unix) 
> >>>>Mapserv 3.6.4 
> >>>>mod_perl 1.22 
> >>>>
> >>>>
> >>>>_______________________________________________
> >>>>Mapserver-users mailing list
> >>>>Mapserver-users at lists.gis.umn.edu
> >>>>http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> >>>
> >>>_______________________________________________
> >>>Mapserver-users mailing list
> >>>Mapserver-users at lists.gis.umn.edu
> >>>http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> >>>
> >>
> >>
> >>_______________________________________________
> >>Mapserver-users mailing list
> >>Mapserver-users at lists.gis.umn.edu
> >>http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> > 
> > 
> > _______________________________________________
> > Mapserver-users mailing list
> > Mapserver-users at lists.gis.umn.edu
> > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> > 
> 
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users




More information about the mapserver-users mailing list