NYCPHP Meetup

NYPHP.org

[nycphp-talk] Saving variable value

Hans Zaunere lists at zaunere.com
Tue Jan 10 22:52:11 EST 2006


Hi Amir,

Amir Aavani wrote on Tuesday, January 10, 2006 1:29 AM:
> Hi Hans ,
> 
> Can I store the an object(class) in a session?
> I though session's can only hold string values!
> or you mean I have to add ToString and LoadFromString function to my
> class.

You can store almost anything in a PHP session.  Be sure to read up session
and object behavior in these cases though:

http://us3.php.net/manual/en/ref.session.php
http://us3.php.net/manual/en/function.serialize.php

Objects are serialized when they are stored in sessions and the
__sleep/__wakeup magic methods become relevant.
 
> > There are, and they are called sessions, but it's likely not what you
> > need for this particular case.  You could, however, use a session to
> > store the currently viewed file of data, and then change the session as
> > needed to display other types of data. 
> > 
> > Best,
> > 
> Also, Is it  a good idea that php parse every .php file. why not
> generating something smaller and simpler to be parsed, for example
> generating a .php.parsed file ( which is a binary file instead of
> textile) for every .php, in which  "for" strings replaced with code "1",
> "while" replaced with "2" and ... , something like Java bytecodes. I
> think this may be result in faster execution. It may be usefully if you
> don't want the web-host to use or change your codes.

There are a number of accellerators out there that do this type of thing.
However, in the large majority of web sites, you won't have the performance
needs, especially if the application is written well.  PHP isn't nearly as
heavy as Java in this respect.

> Why not using a multi thread application, a main thread which accepts
> requests from apache and this thread itself create new threads for every
> new request and can share its variables to these thread?

Threading in PHP is still an issue that's commonly under discussion.  For
someone looking to get started in PHP and write basic applications, let's
save that discussion for another time.  Long story short, PHP is a process
based language.



---
Hans Zaunere / President / New York PHP
   www.nyphp.org  /  www.nyphp.com





More information about the talk mailing list