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


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:-



$request = ms_newowsrequestobj();
$oMap = ms_newMapObjFromString($mapFileString);

..then do your stuff here


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):-



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:


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.