2009/5/14 Peter Ford <p...@justcroft.com>:
> I'm sure I've seen something about this before, but I can't find it:
> I'm creating a file which needs to live for the duration of a session, and
> the duration of the session.
> I made a little call which holds the name of the file like this:
> class __TFR
> private $file;
> public function __construct()
> $this->file = '/tmp/'.session_id().'.xml';
> public function __get($name)
> if ($name=='file') return $this->file;
> public function __destruct()
> So I create an instance of this object and I put a reference to the object in
> the session:
> $_SESSION['TFR'] = new __TFR();
> I was then expecting TFR::__destruct() to only be called when the session was
> closed, with either a timeout, or a session_destroy() call.
> But it looks like the object destructor is called at the end of every page.
> Any ideas about working around that?
The destructor will be called at the end of each page request because
the object in memory is destroyed.
When the object is serialized you will get __sleep being called, and
when it's unserialized you'll get __wakeup.
There is no way to detect when a session is destroyed unless you
implement your own session handler.
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php