#11 - Notifications on PHP Error
Date: 2018-06-02 12:00 - JS
Get a notification if an error occurred in your PHP website.
register_shutdown_function(function() {
$error = error_get_last();
// notify only if there is an error and it's not a notice or warning
if ($error != null && ($error['type'] & (E_NOTICE | E_WARNING)) === 0 && $_SERVER['REMOTE_ADDR'] != '::1') {
$message = 'data:text/plain;base64,' . base64_encode(print_r($error, true));
$content = '{"title":"icy.pt error","body":"An error occurred!","requireInteraction":true,"url":' . json_encode($message) . '}';
$context = stream_context_create(['http' => ['method' => 'POST', 'header' => 'Content-type: application/json', 'content' => $content]]);
// visit https://notifier.icy.pt/ to register your endpoint for free
@file_get_contents('https://notifier.icy.pt/U8w3xcWn3_E029XMM-nX1JmyhbRCAKBU9CMnuuEu00o', false, $context);
}
});