Once i initiated a function i am setting a flag on DB to TRUE.
and i need to set it FALSE on the end of the function.
Ex:
Class Preprocessor extends Machine{
function process(){
$this->db->setValue(TRUE); //Setting DB flag to TRUE
//OTHER CODES
$this->close_db_value(); // Setting DB flag to FALSE
}
function close_db_value(){
$this->db->setValue(FALSE); //Setting DB flag to FALSE
}
}
As you can see that it will work in normal cases, But if some error encountered in //OTHER CODES section then it will not execute the rest of codes.
The function mainly work in background (But not as a command line,its just closing the connection and start executing on background).
How can i ensure that the close_db_value() function executed upon script termination ?
Some of possibilities
- Some critical errors that which leads the script to termination
exitcalled somewhere on the //OTHER CODE section- PHP
max_execution_timeexceeded - A Force Kill
Please help.
try { ... } finally { ... }block should always execute the finally block, no matter if there was a fatal error or not. I have no idea if it will execute in the latter three cases though. See the documentation.