通过Email发送PHP错误的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了通过Email发送PHP错误的方法。分享给大家供大家参考。具体实现方法如下:

<?php
// Our custom error handler
function nettuts_error_handler($number, $message, $file, $line, $vars){
  $email = "
    <p>An error ($number) occurred on line
    <strong>$line</strong> and in the <strong>file: $file.</strong>
    <p> $message </p>";
  $email .= "<pre>" . print_r($vars, 1) . "</pre>";
  $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  // Email the error to someone...
  error_log($email, 1, 'you@youremail.com', $headers);
  // Make sure that you decide how to respond to errors (on the user's side)
  // Either echo an error message, or kill the entire project. Up to you...
  // The code below ensures that we only "die" if the error was more than
  // just a NOTICE.
  if ( ($number !== E_NOTICE) && ($number < 2048) ) {
    die("There was an error. Please try again later.");
  }
}
// We should use our custom function to handle errors.
set_error_handler('nettuts_error_handler');
// Trigger an error... (var doesn't exist)
echo $somevarthatdoesnotexist;

希望本文所述对大家的php程序设计有所帮助。

相关文章

Linux平台PHP5.4设置FPM线程数量的方法

本文实例讲述了Linux平台PHP5.4设置FPM线程数量的方法。分享给大家供大家参考,具体如下: PHP5.4安装完毕后,FPM的默认配置文件位于/usr/local/php/etc/...

详解php设置session(过期、失效、有效期)

在php中设置session有很多方面包有给session设置值或直接设置过期、失效和有效期,下面小编来给大家给各位朋友介绍怎么使用。 我们先来看看在php.ini中session怎么设...

PHP 使用openssl 扩展实现公钥加密的方法

如下所示: // 生成私钥 # openssl genrsa -out rsa_private_key.pem 1024 // 生成公钥 # openssl rsa -in rsa_...

php去掉URL网址中带有PHPSESSID的配置方法

这种情况主要是出现在Linux平台下才能出现,主要是因为php.ini中session.use_trans_sid 配置的问题。 设置php.ini中的session.use_trans...

PHP使用文件锁解决高并发问题示例

本文实例讲述了PHP使用文件锁解决高并发问题。分享给大家供大家参考,具体如下: 新建一个.txt文件,文件中什么都不用写。 【一】.阻塞(等待)模式:(只要有其他进程已经加锁文件,当前进...