When is __destruct called on an object in $_SESSION ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 ONLY
the duration of the session.
I made a little call which holds the name of the file like this:
<?php
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()
    {
        @unlink($this->file);
    }
}
?>
So I create an instance of this object and I put a reference to the object in
the session:

<?php
    $_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?


-- 
Peter Ford                              phone: 01580 893333
Developer                               fax:   01580 893399
Justcroft International Ltd., Staplehurst, Kent

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux