# How to call a mapserver mapscript?

The docuentation leaves me in the dark about this. We used to call static mapfiles directy by:

 http://www.domain.com/cgi-bin/mapserv?map=/var/www/mapfiles/mf.map?[parameters]


But now I want to call a mapscript instead of the mapfile directly.

How do I do this?

EDIT: i'm using PHP mapscript 4.10, on mapserver 5.03. PHP is not configured to run as CGI.

• The link provided by unicoletti, below, helped me on my way – jorrebor Sep 24 '13 at 8:14

Assuming you are programming in say php:-

Create a file map.php in your cgi-bin along the lines of:-

<?php

dl("php_mapscript_4.10.0.dll");

$request = ms_newowsrequestobj();$request->loadparams();
$mapFileString = 'BUILD YOUR MAP FILE AS A STRING';$oMap = ms_newMapObjFromString(\$mapFileString);

?>


This avoids the need to open a static mapfile which is what I think you are asking

It would be called by (for example if your were creating a WMS service):-

http://www.domain.com/cgi-bin/map.php?service=WMS&version=1.1.1&Request=GetCapabilities

Mapserver mapscript is a wrapper around the mapserver APIs that exposes them to a host programming language. Supported programming languages are: Python, Java, C#, Perl, Ruby, Tcl. PHP is also supported, it only differs from the others in how the API is exposed to the PHP interpreter.

That being said one of the ways you could invoke mapscript is by creating a script which simply emulates the behaviour of a standard, Mapserver-backed, WMS service. There are some examples here:

http://mapserver.org/ogc/mapscript.html

There are several reasons for doing this: interpolation of results or input params, alteration of the resulting image, caching, accounting, etc.

If instead what you are aiming for is using a scripting language to dynamically alter your mapfile depending on certain conditions you can of course achieve that through mapscript, but you should also know there is effort underway to embed a javascript interpreter in Mapserver for this very purpose. Note: this feature is limited, not complete and still experimental, YMMV.