Re: [mapserver-users] Re: php mapscript objects in session?
Dear List, I would like to open a little debate about the objects persistence in a session. I found objects persistence very useful and, in my little experience, I get no problems like sharing objects across different sessions or data loss. In fact I entrust the thread safety systems of the environment, and I don't lock threads at application level. Methods to make persistent mapscripts objects in sessions vary according to the web engine used. I know only php and ASP.NET environments: php can only store primitives as strings, floats, integers; ASP.NET can instead store instanciated objects, like mapscript objects. In fact, php don't store the variables in memory but write a session file to re-read on the next postback, so the app must to re-istanciate the object according to a saved set of parameters, like extent-coordinates, layers status ... So I'm a bit amazed (read: worried) reading recent posts like: And even if it was possible it is NOT recommended to reuse mapscript objects across requests... Ah, MapScript object persistence... the restless leg syndrome of MapServer. Though neither convenient nor pretty, the One True Way (TM) to persist MapScript objects is the mapfile format. Every other approach will just cause hair loss, unexplained rashes, nausea, and memory leakage. Why you don't recommend this methods? can you pls share your experience, before my hairs fall :) ? regards .. pg -- Pietro Giannini Bytewise srl - Area GIS 41°50'38.58N 12°29'13.39E ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Re: php mapscript objects in session?
jim white wrote: I searched Mapserver site for UpdateFromString and found only MS RFC 31: Loading MapServer Objects from Strings. I was able to use the save function and print out the file which did work. However, my 2 attempts failed. $map-UpdateFromString('saved_map.txt'); got Call to undefined method ms_map_obj::UpdateFromString() and $map2 = msLoadMapFromString('saved_map.txt'); got Call to undefined function msLoadMapFromString() I am using mapserver 5.0.0 It seems that the updateFromString() methods were never implemented in PHP MapScript. We'll try to work on that soon and get them in 5.4. Here is the related ticket: http://trac.osgeo.org/mapserver/ticket/2298 Note that there is no updateFromString() on the mapObj, only on the individual object classes that compose a map (layerObj, classObj, etc.). To instantiate a map from a saved file, you can pass the path to the saved mapfile the mapObj constructor itself. Actually, here is a list of the classes that implement updateFromString(), from a quick grep of the SWIG MapScript code: class.i:int updateFromString(char *snippet) label.i: int updateFromString(char *snippet) layer.i:int updateFromString(char *snippet) legend.i: int updateFromString(char *snippet) querymap.i: int updateFromString(char *snippet) referencemap.i: int updateFromString(char *snippet) scalebar.i: int updateFromString(char *snippet) style.i:int updateFromString(char *snippet) web.i:int updateFromString(char *snippet) Daniel -- Daniel Morissette http://www.mapgears.com/ ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Re: php mapscript objects in session?
Howard Butler wrote: On Nov 21, 2008, at 5:35 PM, jim white wrote: There must be a way to persist a mapscript object, but I don't know enough of OO design to tell you the answer. Ah, MapScript object persistence... the restless leg syndrome of MapServer. Though neither convenient nor pretty, the One True Way (TM) to persist MapScript objects is the mapfile format. Every other approach will just cause hair loss, unexplained rashes, nausea, and memory leakage. The UpdateFromString and save methods are the way to go. Your target MapScript language has no problem persisting strings, and you don't have to worry about the mess of object lifetimes that might result from trying to light up a once dead mapObj. Howard I searched Mapserver site for UpdateFromString and found only MS RFC 31: Loading MapServer Objects from Strings. I was able to use the save function and print out the file which did work. However, my 2 attempts failed. $map-UpdateFromString('saved_map.txt'); got Call to undefined method ms_map_obj::UpdateFromString() and $map2 = msLoadMapFromString('saved_map.txt'); got Call to undefined function msLoadMapFromString() I am using mapserver 5.0.0 Jim -- James (Jim) B. White tel: (919)-380-9615 homepage: http://jimserver.net/ ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users
RE: [mapserver-users] Re: php mapscript objects in session?
-Original Message- From: [EMAIL PROTECTED] [mailto:mapserver-users- [EMAIL PROTECTED] On Behalf Of jim white Sent: Friday, November 21, 2008 9:19 AM To: mapserver-users@lists.osgeo.org Subject: [mapserver-users] Re: php mapscript objects in session? Hi- I'm using ms4w 2.2.7 and I've run into a problem. Ideally I'd like to create the MapScript map object and store it in the session: $_SESSION['map'] = ms_newMapObj($getMapPath); This works fine for the that page, for the first call, but when I attempt to reference it later I get a PHP error: Fatal error: Object has an invalid _handle_ property Am I missing something here? Thanks, -Chris Chris, When you attempt to start a session, you need to load the class definition first. For example ?php require('myclass.php'); session_start(); ? Hi Jim- Thanks for responding... Actually, I can store non MapScript objects in the $_SESSION just fine, but when I attempt to either: 1) add the MapScript object as a private member of my class 2) simply save the MapScript object to the $_SESSION and then reuse, I get the error. Have you managed to store MapScript objects in sessions? -Chris ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users
Re: [mapserver-users] Re: php mapscript objects in session?
Christopher Condit wrote: -Original Message- From: [EMAIL PROTECTED] [mailto:mapserver-users- [EMAIL PROTECTED] On Behalf Of jim white Sent: Friday, November 21, 2008 9:19 AM To: mapserver-users@lists.osgeo.org Subject: [mapserver-users] Re: php mapscript objects in session? Hi- I'm using ms4w 2.2.7 and I've run into a problem. Ideally I'd like to create the MapScript map object and store it in the session: $_SESSION['map'] = ms_newMapObj($getMapPath); This works fine for the that page, for the first call, but when I attempt to reference it later I get a PHP error: Fatal error: Object has an invalid _handle_ property Am I missing something here? Thanks, -Chris Chris, When you attempt to start a session, you need to load the class definition first. For example ?php require('myclass.php'); session_start(); ? Hi Jim- Thanks for responding... Actually, I can store non MapScript objects in the $_SESSION just fine, but when I attempt to either: 1) add the MapScript object as a private member of my class 2) simply save the MapScript object to the $_SESSION and then reuse, I get the error. Have you managed to store MapScript objects in sessions? -Chris Chris, No I haven't saved a Mapscript object. Perhaps this is more a response to another post that said you could only access session variables, and not classes, from another page. However, you might try replacing require('myclass.php'); with if(!extension_loaded('MapScript')){ dl(php_mapscript.so); } There must be a way to persist a mapscript object, but I don't know enough of OO design to tell you the answer. Jim -- James (Jim) B. White tel: (919)-380-9615 homepage: http://jimserver.net/ ___ mapserver-users mailing list mapserver-users@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/mapserver-users