Thrown exceptions not halting app
Posted: Wed Feb 13, 2008 4:10 pm
This sounds weird to me but I have to ask...
Can a PHP app that throws an uncaught exception still process and output even though an exception was raised and thrown and written to the error log?
I ask this because today I finally figured out what was causing another problem I was having (namely multiple orphaned mysql instances). I realized that something was opening a connection to my database server but was never closing it out. This was happening to the tune of 9 to 20 connections per server request. What I found in my investigation was that my RewriteRules were not behaving as expected and requests that were being made for files and directories, though I told the server to skip them, were being routed through my frameworks bootstrap file.
Upon more investigation I found that requests for a JS (for example) were being made to http://mysite.com/Layout/Default/Default.js and were resulting in 404 errors within my framework. To the framework this meant that instead of serving up a requested page the app would instead serve up the doPageNotFound() found method of my Index controller and would attempt to parse the PageNotFound.php view.
However I forgot to actually put the view in the proper path so this view was throwing a View_Exception in my framework. However, this exception never halted execution of the main script. So everything ran hunky dory like nothing was wrong.
But something was wrong. The component controllers were dying on each request. And Rewrite handling was not working, so every source file for a given page request (whether it was a PHP component controller in the app or a CSS file from the view) was resulting in a 404, an open DB connection, an uncaught thrown exception and an orphan database connection.
My question is, why would an uncaught exception in a component controller or any other piece of an application not halt output of the script? I am baffled by this and would love someone with more PHP knowledge than me to help me understand what the hell is going on with this.
Can a PHP app that throws an uncaught exception still process and output even though an exception was raised and thrown and written to the error log?
I ask this because today I finally figured out what was causing another problem I was having (namely multiple orphaned mysql instances). I realized that something was opening a connection to my database server but was never closing it out. This was happening to the tune of 9 to 20 connections per server request. What I found in my investigation was that my RewriteRules were not behaving as expected and requests that were being made for files and directories, though I told the server to skip them, were being routed through my frameworks bootstrap file.
Upon more investigation I found that requests for a JS (for example) were being made to http://mysite.com/Layout/Default/Default.js and were resulting in 404 errors within my framework. To the framework this meant that instead of serving up a requested page the app would instead serve up the doPageNotFound() found method of my Index controller and would attempt to parse the PageNotFound.php view.
However I forgot to actually put the view in the proper path so this view was throwing a View_Exception in my framework. However, this exception never halted execution of the main script. So everything ran hunky dory like nothing was wrong.
But something was wrong. The component controllers were dying on each request. And Rewrite handling was not working, so every source file for a given page request (whether it was a PHP component controller in the app or a CSS file from the view) was resulting in a 404, an open DB connection, an uncaught thrown exception and an orphan database connection.
My question is, why would an uncaught exception in a component controller or any other piece of an application not halt output of the script? I am baffled by this and would love someone with more PHP knowledge than me to help me understand what the hell is going on with this.