Opened 14 years ago

Closed 14 years ago

#3470 closed defect (invalid)

catching stdout with ms_ioinstallstdouttobuffer() fails on map->saveImage('',$mapfile)

Reported by: milovanderlinden Owned by: aboudreault
Priority: normal Milestone: 6.0 release
Component: MapScript-PHP Version: unspecified
Severity: normal Keywords:
Cc: dmorissette

Description

I tried the following sequence:

//initialize stdout redirection
 ms_ioinstallstdouttobuffer();
//create mapfile ref
 $oMap = ms_newMapobj("mapserver/topo.map");
//do some (unimportant) things with the map
 $oMap->set('width', 100);
 $oMap->set('height', 100);
 $oMap->setextent(0,0,2,2);
//draw the image resulting from the map and the current viewpoint settings
 $image = $oMap->draw();
//save the image to stdout. This is where it misbehaves: I am expecting stdout to be caught by the ms_io, but instead it renders to my php page.

 $saveresult = $image->saveImage('',$oMap);

//the rest of the steps don't work but describe the way the sequence should be handled.
 $contenttype = ms_iostripstdoutbuffercontenttype();
 $buffer = ms_iogetStdoutBufferBytes();
 $returnvalue = base64_encode($buffer);
 ms_ioresethandlers();
 return $returnvalue;

This sequence works perfectly when instead of using saveImage, you use owsdispatch.

Change History (2)

comment:1 by dmorissette, 14 years ago

Cc: dmorissette added
Milestone: 6.0 release
Owner: changed from mapserverbugs to aboudreault

Which version of MapServer/MapScript, and PHP?

comment:2 by aboudreault, 14 years ago

Resolution: invalid
Status: newclosed

milovanderlinden, the reason why the stdout is not caught is because the image bytes are written by php (in the saveImage() function) and not by the mapserver library. ms_ioinstallstdouttobuffer() can only be used when the output is printed by mapserver. ie. wms/wfs requests. There aren't many functions that use the php functions to write the output data... but saveImage does. For that particular case, you have to use the php ob_start() function. ie:

ob_start();
$image->saveImage('',$oMap);
$buffer = ob_get_contents();
ob_end_clean();
Note: See TracTickets for help on using tickets.