Re: [PHP] store class zithin session
Hi Stut, On Thu, Nov 20, 2008 at 12:25 PM, Stut <[EMAIL PROTECTED]> wrote: > On 20 Nov 2008, at 11:01, Alain Roger wrote: > >> i have a class and i would like to store it zithin session. >> i was thinking to use serialize/unserialize but it does not work. >> >> any idea how to do it ? >> > > Alain, you've been on this list long enough to know that "it does not work" > is not enough information for people to be able to help you. > You're right and i feel sorry. i thought i paste my code just after the sentence. ok, anyway i solved my problem somehow :-) > > Firstly there is no need to serialise anything going into the session. > Secondly I assume you want to store objects not classes. yes. > Thirdly there is no reason why it should not work, but there are some > caveats you need to be aware of... > > * The class definition must have been loaded before session_start() is > called, otherwise you'll end up with an object of type stdClass rather than > your class. this was my mistake...i mean to not call the class file before starting the session :-( A.
Re: [PHP] store class zithin session
On Thu, Nov 20, 2008 at 2:51 PM, Stut <[EMAIL PROTECTED]> wrote: > On 20 Nov 2008, at 19:35, Eric Butera wrote: >> >> Well I wouldn't put objects into the session to begin with. > > Why not? I do it all the time and it works fine. > >> I was >> just talking about this specific case. Wouldn't autoload be fine if >> the file was already in the opcode cache? > > Opcode caches work during the compilation phase, so any dynamic loading such > as that provided by autoloaders cannot be optimised. This has been discussed > in the past on this list, check the archives for more details. > > -Stut > > -- > http://stut.net/ > http://till.vox.com/library/post/zendframework-performance.html?_c=feed-rss-full Item #3: Get rid off require_once, use __autoload (and the Zend_Loader) It just lead me to believe that after autoload found a class it somehow cached the code for it. I'll look into this when I get some free time for testing. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] store class zithin session
On 20 Nov 2008, at 19:35, Eric Butera wrote: Well I wouldn't put objects into the session to begin with. Why not? I do it all the time and it works fine. I was just talking about this specific case. Wouldn't autoload be fine if the file was already in the opcode cache? Opcode caches work during the compilation phase, so any dynamic loading such as that provided by autoloaders cannot be optimised. This has been discussed in the past on this list, check the archives for more details. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] store class zithin session
This one time, at band camp, "Alain Roger" <[EMAIL PROTECTED]> wrote: > Hi, > > i have a class and i would like to store it zithin session. > i was thinking to use serialize/unserialize but it does not work. http://www.phpro.org/tutorials/Introduction-To-PHP-Sessions.html#8 Kevin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] store class zithin session
On Thu, Nov 20, 2008 at 2:07 PM, Jochem Maas <[EMAIL PROTECTED]> wrote: > Eric Butera schreef: >> On Thu, Nov 20, 2008 at 8:37 AM, Yeti <[EMAIL PROTECTED]> wrote: > > ... > >>> >> >> Autoload. Why on earth would you do such a thing? > > autoload ... your neighbourhood opcode cache performance killer, > then again so is file based sessions (for ease of use I stick > my session files on /dev/shm/foo [i.e. RAM] if/when using a > file based session handler ... I figure if the box goes down and > takes /dev/shm with it the lost session data is the least of > my worries ... besides by the time the box is up current visitors > will generally have given up and left already) > > ... and storing a path to > a file containing a serialized object in the session is a bit nuts, > you might as well store the serialized object in the session and > save at least one file write/read. storing a serialized object, > as opposed to letting the session handler do transparent serialization > can help you get round an infrastructure problem (where you can't > load the class before starting the session) and also can improve > performance where you might not want/need to initialize the > given object on every request. > >> > > Well I wouldn't put objects into the session to begin with. I was just talking about this specific case. Wouldn't autoload be fine if the file was already in the opcode cache? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] store class zithin session
Eric Butera schreef: > On Thu, Nov 20, 2008 at 8:37 AM, Yeti <[EMAIL PROTECTED]> wrote: ... >> > > Autoload. Why on earth would you do such a thing? autoload ... your neighbourhood opcode cache performance killer, then again so is file based sessions (for ease of use I stick my session files on /dev/shm/foo [i.e. RAM] if/when using a file based session handler ... I figure if the box goes down and takes /dev/shm with it the lost session data is the least of my worries ... besides by the time the box is up current visitors will generally have given up and left already) ... and storing a path to a file containing a serialized object in the session is a bit nuts, you might as well store the serialized object in the session and save at least one file write/read. storing a serialized object, as opposed to letting the session handler do transparent serialization can help you get round an infrastructure problem (where you can't load the class before starting the session) and also can improve performance where you might not want/need to initialize the given object on every request. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] store class zithin session
On Thu, Nov 20, 2008 at 8:37 AM, Yeti <[EMAIL PROTECTED]> wrote: > If you can't load the class before calling session_start you can store > the serialized object in a file and simple set a > $_SESSION['path_to_file'] session variable.. > > EXAMPLE: > session_start(); > > //some code > > class apple_tree { > var $apples = 17; > } > > $temporary_file = 'appletree.txt'; > $file_content = serialize(new apple_tree()); > > if ($fp = fopen($temporary_file, 'w')) { > fwrite($fp, $file_content); > $_SESSION['path_to_file'] = $temporary_file; > fclose($fp); > } > > ?> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Autoload. Why on earth would you do such a thing? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] store class zithin session
If you can't load the class before calling session_start you can store the serialized object in a file and simple set a $_SESSION['path_to_file'] session variable.. EXAMPLE: -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] store class zithin session
On 20 Nov 2008, at 11:01, Alain Roger wrote: i have a class and i would like to store it zithin session. i was thinking to use serialize/unserialize but it does not work. any idea how to do it ? Alain, you've been on this list long enough to know that "it does not work" is not enough information for people to be able to help you. Firstly there is no need to serialise anything going into the session. Secondly I assume you want to store objects not classes. Thirdly there is no reason why it should not work, but there are some caveats you need to be aware of... * The class definition must have been loaded before session_start() is called, otherwise you'll end up with an object of type stdClass rather than your class. * Resources stored inside the object must be cleaned up in __sleep() and can be recreated in __wake() as they will not be stored in the session along with the rest of the object. If you still can't get it to work after reading this, send us the code. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php