NYCPHP Meetup

NYPHP.org

[nycphp-talk] DB-based sessions and destructing objects problem

Cliff Hirsch cliff at pinestream.com
Mon Apr 2 10:27:06 EDT 2007


I am implementing a MySQL-based session handler and am confused by the dialog
in the PHP manual regarding this issue:

"Write and Close handlers are called after destructing objects since PHP
5.0.5. Thus destructors can use sessions but session handler can't use
objects. In prior versions, they were called in the opposite order. It is
possible to call session_write_close() from the destructor to solve this
chicken and egg problem."

The English please....

First, my app uses PEAR DB. So should I use PEAR DB for access, or use the
mysql or mysqli primitives and open a new connection? It seems like opening a
new connection would be a waste of resources. But using PEAR DB adds overhead
and brings up this object destruction problem.

I've seen register_shutdown_function('session_write_close'); as a way to get
around the destructor issue, but what is the PEAR DB class is destructed
before the session handler?

Thoroughly confused...

Thoughts?

Cliff



More information about the talk mailing list