Handling and Notification of Failed DB Connection in PHP -
my web host having issue 1 of databases on website, , i'm getting error message when connection attempted. happened on site, learned instantly, i'm wondering best way sort of notification type of issue in future. first instinct (abbreviated) code block this:
try { $dbh = new pdo("mysql:host=$host;dbname=$dbname", $user, $pass); $dbh->setattribute( pdo::attr_errmode, pdo::errmode_silent); } catch(pdoexception $e) { $msg = $e->getmessage(); mail($to,$subject,$msg,$headers); }
but saw flaw email every single time page hit. had brief thought entering error in database, if there's database connection issue, doesn't seem particularly useful method of learning error.
any other thoughts on how can handle scenario? real time notification preferred, @ notification beyond me accessing website work better have now.
the easiest solution canary / status page checked site uptime monitor, can alert you. if page returns error, text or email.
there of course more complex routes take they'd overkill you're needing.
Comments
Post a Comment