The DBA at my company has a script that automatically kills long-running database connections and queries on our production databases. I\'ve written a CakePHP Shell application
Maybe you could use the callbacks in the AppModel for this.
I'd guess that you could use beforeFind
and beforeSafe
to make a connection to the database and then use afterFind
and afterSafe
to kill your connection.
As for a 'right' way of opening and closing database connections using core Cake functionality, I'm not sure but Costa's answer seems like a good (and clean!) plan.
(1) http://book.cakephp.org/1.3/en/view/922/Database-Configuration (Link stopped working, guess you should look here now: http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Configuration.html )