so I have following problem.
I have a session class that should save it’s data to database at the end of the request execution. Basically, when it is destructed.
I’m using singleton pattern in this case.
I have a destructor like this:
public function __destruct()
{
$this->_save(); // _save is public
// exit('I can reach this point with no error');
}
But with that code I get net::ERR_CONNECTION_RESET from chrome and other browsers.
If I comment out the destructor and place this in constructor:
register_shutdown_function(array($this, '_save'));
The _save method is not returning any Exceptions when I call it directly.
Everything works fine. What could be wrong and why?
Thanks!
Ok, I found the solution. The _save() method was calling some methods that were saving data to database. BUT! The database instance is a SINGLETON, so there were no references anywhere and the database object was already destroyed at this point. The solution was to save the reference to database instance somewhere in the model. Looks like register_shutdown_function was working because nothing was destroyed yet.