Reconnect to database when encountering PDOExceptions with error code in predefined list #47897
Unanswered
ZachWatkins
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Howdy! I've solved this problem for a project using a serverless database and wanted to get feedback on whether the framework maintainers would welcome a pull request to provide this as a feature in the DB facade, a helper function, or in some other way.
I can't share the exact code, but I would need to rewrite it in any case to fit better with the implementation requirements.
The code I wrote implemented the process described here: https://learn.microsoft.com/en-us/azure/azure-sql/database/troubleshoot-common-connectivity-issues?view=azuresql-db#retry-logic-for-transient-errors
The way we implemented it allows me to add a list of error codes to
./config/database.php
. Whenever a database command is run that I need to only retry when it encounters one of these codes, I wrap it in a helper function I designed to execute the retry logic. It also resets the PDO timeout configuration before the first reattempt of the DB query that failed, and uses exponential backoff for subsequent attempts.I welcome your feedback!
Beta Was this translation helpful? Give feedback.
All reactions