Вход Регистрация
* HELL

Ведение лог-файла об ошибках по электронной почте

  1. function nettuts_error_handler($number, $message, $file, $line, $vars){
  2. $email = "
  3. <p>An error ($number) occurred on line
  4. <strong>$line</strong> and in the <strong>file: $file.</strong>
  5. <p> $message </p>";
  6.  
  7. $email .= "<pre>" . print_r($vars, 1) . "</pre>";
  8.  
  9. $headers = 'Content-type: text/html; charset=iso-8859-1' . "rn";
  10.  
  11. // Email the error to someone...
  12. error_log($email, 1, 'you@youremail.com', $headers);
  13.  
  14. // Make sure that you decide how to respond to errors (on the user's side)
  15. // Either echo an error message, or kill the entire project. Up to you...
  16. // The code below ensures that we only "die" if the error was more than
  17. // just a NOTICE.
  18. if ( ($number !== E_NOTICE) && ($number < 2048) ) {
  19. die("There was an error. Please try again later.");
  20. }
  21. }
  22.  
  23. // We should use our custom function to handle errors.
  24. set_error_handler('nettuts_error_handler');
  25.  
  26. // Trigger an error... (var doesn't exist)
  27. echo $somevarthatdoesnotexist;
» Описание: Лог-файлы ошибок очень полезны, но вам ведь нужно уметь читать их на случай, если что-то произойдет. Давайте будет честными: если нам кажется, что все идет хорошо, вряд ли кто-то будет заглядывать в лог-файлы.

Данная функция будет отправлять вам электронное письмо тогда, когда возникает какая-то ошибка на сайте. Очень удобно для того, чтобы всегда быть в курсе происходящего.
» Время добавления: 20 Окт 2015 в 14:28
» Посмотров: 1127
» textarea
» Рейтинг: [+0 | -0]
Комментарии [0]
Онлайн: 2
Реклама