jmckenna at gatewaygeomatics.com
- Last updated:
As of the MapServer 8.0.0 release PHP support is only available through MapServer's SWIG API. The unmaintained native PHP MapScript support was removed.
This is a PHP module that makes MapServer's MapScript functionalities available in a PHP Dynamically Loadable Library. In simple terms, this module will allow you to use the powerful PHP scripting language to dynamically create and modify map images in MapServer.
PHP 5.2.0 or more recent is required; As of MapServer 7.4.0, PHP 7 is available through the SWIG API, and all existing MapServer users are encouraged to update their scripts for the new SWIG syntax; see the MapServer Migration Guide for example syntax.
Support for PHP 4, PHP 5.0 and PHP 5.1 was dropped as of MapServer 6.0. PHP MapScript was originally developed for PHP 3.0.14, and after MapServer 3.5 support for PHP 3 was dropped.
The module has been tested and used on Linux, Solaris, *BSD, and Windows.
How to Get More Information on PHP MapScript¶
For installation questions regarding the PHP MapScript module, see PHP MapScript Installation.
The MapServer Wiki has information on this module, that was contributed by users.
New PHP MapScript users should read the By Example document.
The project's home is the PHP/MapScript page on MapTools.org.
Refer to the main PHP site for their official documentation.
Normally, you should not have to worry about the memory management because php has a garbage collector and will free resources for you. If you write only small scripts that don't do a lot of processing, it's not worth to care about that. Everything will be freed at the end of the script.
However, it may be useful to free resources during the execution if the script executes many tasks. To do so, you'll have to call the free() method of the mapscript objects and unset the php variables. The purpose of the free methods is to break the circular references between an object and its properties to allow the zend engine to free the resources.
Here's an example of a script (using the legacy syntax, not the SWIG API syntax) that doesn't free things during the execution:
$map = new mapObj("mapfile.map"); $of = $map->outputformat; echo $map->extent->minx." - ".$map->extent->miny." - ". $map->extent->maxx." - ".$map->extent->maxy."\n"; echo "Outputformat name: $of->name\n"; unset($of); unset($map); // Even if we unset the php variables, resources // won't be freed. Resources will be only freed // at the end of the script
and the same script that frees resources as soon as it can
$map = new mapObj("mapfile.map"); $of = $map->outputformat; echo $map->extent->minx." - ".$map->extent->miny." - ". $map->extent->maxx." - ".$map->extent->maxy."\n"; echo "Outputformat name: $of->name\n"; unset($of); $map->free(); // break the circular references // at this place, the outputformat ($of) and the rect object // ($map->extent) resources are freed unset($map); // the map object is immediately freed after the unset (before the // end of the script)