[mapserver-users] PHP MapObj serialization?

Daniel Morissette morissette at dmsolutions.ca
Tue Jul 30 09:41:26 EDT 2002


Vinko,

The main reason why you cannot serialize a MapObj in PHP is that it is
just a set of wrappers on top of MapServer's internal C structures, and
hte PHP serialization functions cannot do anything about them... so you
get "invalid handle" errors from the serialized object because the
internal C structures don't exist any more.

In the current version, the only way to save the state of a mapObj is to
use $map->save($temp_filename), store the $temp_filename in your
$_SESSION, and load the saved mapfile on further requests.

I don't think serializing mapObj will ever be possible given the nature
of MapScript, but maybe some tricks can be implemented eventually to
save the mapfile to a session variable, or even have support for
persistent mapObj... but that's very far in our priority list.

Daniel


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,
> --
> Vinko Vrsalovic <vinko[|- at -|]cprsig.cl>
> http://www.cprsig.cl



More information about the mapserver-users mailing list