Reputation: 485
I know PHP closes any open MySQL connection at the end of the script execution, but what happens with connections if a fatal error occurs?
I can't find anything here or on Google.
I use static connections to reuse them. Additionally there is a __destruct()
to close it. On the end of the execution, the destructor is called (I see it in the log-file).
But if I do a fatal error (just to find out what happens), the destructor is NOT called. What happens with the connection?
Upvotes: 6
Views: 1472
Reputation: 160883
Unless you use persistent connection, mysql connection will always be automatically closed at the end of the script's execution.
PHP Fatal error will stop the script's execution, and mysql connection will be released.
Note that in case of mysqli, even if persistent connection is used, the outcome is pretty much the same, as mysqli is calling mysql_change_user() on connect which cleans the state (including rollback) all the same.
Upvotes: 7
Reputation: 42935
The php engine removes any open connections in case of such a crash. Just as when there is no crash. This is a cleanup thing the engine does. Exception: when using presistent connections then the connection is pooled and reused by subsequent scripts.
The destructor you mention is a destructor in your class, probably some wrapper class. There is no reason why php should call that if it closes the connection to the mysql server.
Upvotes: 3