We use the Zend framework for MVC and Pear for accessing the database. I was wondering should I close the connection to the database everytime a request is completed? And if so is there a way to do this elegantly?
We have about 50 actions spread across multiple controllers, and I don't really want to put db->disconnect() at the end of each controller. Is there a way that I can put this disconnect command in one location, a "destructor" if you will, and have Zend call this automatically whenever a request is completed?
At the moment I can think of two possibilities that you could consider.
First, you could put your "destructor" in a controller plugin in e.g. dispatchLoopShutdown hook.
Second, if you really want something to be executed at the very end of you request, you could put your "destructor" after $application->bootstrap()->run();
in your index.php.