PHP MapScript

Author:

Jeff McKenna

Contact:

jmckenna at gatewaygeomatics.com

Last updated:

2019-05-25

Peringatan

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.

Introduction

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.

Versions Supported

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.

Catatan

If you are using MapServer 5.6 and older, please refer to the PHP MapScript 5.6 documentation instead.

Catatan

If you are migrating your existing application that is based on MapServer 5.6 or older, to MapServer 7.4 or beyond, please read the PHP MapScript Migration Guide for important changes.

Windows Binaries

PHP 7+ mapscript is included in MS4W, the popular installer maintained by Gateway Geomatics. You can also see user-contributed PHP 7 scripts through the SWIG API, on the MS4W wiki.

How to Get More Information on PHP MapScript

Memory Management

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)