[mapserver-users] Designing a wrapper around mapserv which can be used with fcgi
Adrian Popa
adrian_gh.popa at romtelecom.ro
Mon Nov 2 22:31:02 PST 2009
Thank you,
I will look into it. I guess through mapscript I can redefine the
parameters that get sent to mapserver? Or do I rewrite the whole map?
Andy Colson wrote:
> Adrian Popa wrote:
>> Hello everyone,
>>
>> I am currently using a wrapper around mapserv which receives the URL
>> parameters, builds the map file (actually I only need to set some
>> filters in the map file, but the filters need to be built after
>> running some SQL queries with the passed in parameters). After the
>> map file is built, mapserv is called (as a shell script), and the map
>> gets sent to the user. Currently this wrapper is written in perl - so
>> it's not terribly fast as a cgi process.
>>
>> While this approach works, it is terribly inefficient. I would like
>> to use mapserv as a fcgi process (or something faster than plain
>> cgi). My question is - how can I /should I build a wrapper around
>> mapserv that can "customize" the MAP file on the fly and run as a
>> fcgi process?
>>
>> Any ideas on where I should start? An example of such a wrapper?
>>
>> Also, I suspect I can send parameters to mapserver and use some sort
>> of variables in the map file to set up my filters - but I haven't
>> seen an example. Can someone point me to such a documentation?
>>
>> Thanks,
>> Adrian
>
> Have you seen mapscript? You can use mapserver directly from perl.
> And perl can do fast-cgi. Here is a little, ad-hoc, non-tested, perl
> fcgi:
>
>
> #!/usr/bin/perl
>
> use strict;
> use mapscript;
> use FCGI;
>
>
> my $request = FCGI::Request( );
> while($request->Accept() >= 0)
> {
> my($req, $x, $at, $xmap, $xpin, $sid, $y, $q);
>
> $req = new mapscript::OWSRequest();
> $req->loadParams();
>
> $xmap = $req->getValueByName('map');
> $xpin = $req->getValueByName('pin');
>
> my $map = new mapscript::mapObj( "/maps/$xmap.map" );
> if (! $map)
> {
> #print STDERR "----- Error loading map: $xmap.map\n";
> print("Content-type: text/text\r\n\r\n");
> print "cant load $xmap.map";
> $request->Finish();
> next;
> }
>
> mapscript::msIO_installStdoutToBuffer();
>
> $x = $map->OWSDispatch( $req );
> if ($x)
> {
> print STDERR "OWSDispatch: $x\n";
> my $errObj = new mapscript::errorObj();
> while ($errObj) {
> print STDERR "ERROR:
> $errObj->{code}:$errObj->{message}:$errObj->{routine} \n";
> $errObj = $errObj->next();
> }
> }
>
> my $content_type =
> mapscript::msIO_stripStdoutBufferContentType();
>
> $x = mapscript::msIO_getStdoutBufferBytes();
>
>
> print("Content-type: $content_type\r\n\r\n");
> if (mapscript::msGetVersionInt() >= 50500)
> {
> print $$x;
> } else {
> print $x;
> }
>
> mapscript::msIO_resetHandlers();
> $request->Finish();
> }
>
>
>
> I'd recommend using mapserver 5.6.0.
>
> -Andy
>
More information about the MapServer-users
mailing list