[mapserver-users] PHP MapObj serialization?
Paul Spencer
pagameba at magma.ca
Tue Jul 30 06:45:43 PDT 2002
It is not possible to serialize a map object in this way. We needed to
do this for MapLab, so we added a feature to the MapScript 3.6.1 branch
to allow a map file to be loaded from one directory but to make all the
internal references relative to another directory.
If you are using MapScript 3.6.1 or later, you should be able to use
this new feature. A simple test would be to write a short script:
<?
dl( "php_mapscript.so" );
$map = ms_newMapObj( "/path/to/mapfile/mapfile.map", "/path/to/mapfile" );
?>
if it doesn't complain then you are using a new enough version. Now you
can save the map object to a temporary location and save the temporary
name in the session. You also need to store the directory name that the
original map file came from.
$_SESSION['map_directory'] = "/path/to/map/file";
$_SESSION['temp_map'] = "/tmp/12345678.map";
then when you load the next page and decide to restore this map object,
$map = ms_newMapObj( $_SESSION['temp_map'], $_SESSION['map_directory'] );
Cheers,
Paul Spencer
Applications and Software Development
DM Solutions Group
Vinko Vrsalovic wrote:
>Hello,
>
> I'm trying to serialize a PHP MapObj for further use (another
> page from the same session).
>
> From what I've read, this will not work if you don't have the
> definition of the class in all the pages the object will be
> used.
>
> I also presume that dl'ing the .so is not what is meant by
> definition of the class. Is serializing and/or saving in a
> session variable the mapobj possible?
>
> Ex:
>
> p1.php
> <?php
> dl('php_mapscript.so');
> session_start();
> $map = ms_newMapObj("file.map");
> $map->draw();
>
> $_SESSION['map'] = $map;
> /* or
> $_SESSION['map'] = serialize($map);
> */
>
> ?>
>
> p2.php
> <?php
> dl('php_mapscript.so');
> session_start();
> $map = $_SESSION['map'];
> /* or
> $map = unserialize($_SESSION['map']);
> */
>
> ?>
>
> As I understood from the docs the serialization is not needed when
> using $_SESSION.
>
> If i serialize/unserialize, i get the long forgotten:
>
> Fatal error: Object has an invalid _handle_ property in ...
>
> If i don't serialize/unserialize, i get the same error. :)
>
> Is there a trick to make PHP see the MapObj definition?
>
>Thanks,
>
>
More information about the MapServer-users
mailing list