PHP向服务器错误记录、文件或远程目标发送一个错误


1、用到的函数说明 php

1语法: error_log(error, type, destination, headers) web

2 参数说明: ubuntu

    error: 必需, 要记录的错误消息 vim

    type: 可选。规定错误记录的类型, 可能的看记录类型: 服务器

        0 - 默认, 根据在php.ini文件中的error_log配置,错误被发送到服务器日志系统或文件 函数

        1 - 错误被发送到destination参数中的地址,只有该类型使用headers参数 php-fpm

        2- 经过PHP debugging连接来发送错误。该喧嚣只在PHP 3 中使用 spa

        3- 错误发送到文件目标字符串 debug

    destination:可选,规定向何处发送错误消息,该参数的值依赖于"type”参数的值 rest

    headers:可选, 只有”type“为1时使用。规定附加的头部, 好比From, Cc已经Bcc。有CRLF(\r\n)分隔

        注意:在发送电子邮件时,必须包含From头部。能够在php.ini文件中或这经过此参数设置

3 小知识点:

(1)写电子邮件Cc是Carbon Copy 意为复写的副本,就是咱们一般说的抄送

(2)Bcc是Blind Carbon Copy ,意为隐蔽副本,密送。发给谁,除了你跟密送的对象外谁都不知道

(3)抄送与密送的区别:同时发同一篇邮件给不少人时,用抄送的话收件人就知道还有谁也收到了该邮件,用密送,则收件人就不知道还有谁一样也收到了该邮件

2、示例:

/**
 * 发送一封带有自定义错误的电子邮件
 */
 $test = 2;
 if($test > 1){
     echo "eee\n";
     error_log("A custom error has been triggered", 1, "792294380@qq.com", "From: webmaster@example.com");
     echo "eee2\n";
 }

3、问题解决

1 问题:sh: 1: /usr/sbin/sendmail: not found

2 出现缘由:没有启动或安装sendmail组件

3 解决办法:

(1)安装sendemial: ubuntu系统下的安装方法之一, sudo apt-get install sendemail

(2)重启php-fpm进程: sudo /etc/init.d/php-fpm restart, 我使用了sudo /etc/init.d/php-fastcgi restart

(3)检测sendemail是否运行正常: sudo /etc/init.d/sendmail status,若是现实正在运行running就能够

    可能用到的命令:

    sudo /etc/init.d/sendmail start (启动sendmial)

    sudo /etc/init.d/sendmail stop (关闭sendmail)

    sudo /etc/init.d/sendmial restart(重启sendmail)

(4)配置php.ini, 填写sendmial的绝对路径

    1>查找php的安装目录: locate php5, 例如查找到在/usr/share/中

    2>填写sendmail的绝对路径:

       a:打开php的配置文件php.init,例如sudo vim /usr/share/php5/php.ini-development 

        b:输入?sendmail_path查找定位

        c:编辑修改sendmail_path配置,sendmail_path = /usr/share/sendmial -t -i

(5)重启php-fpm进程: sudo /etc/init.d/php-fpm restart

相关文章
相关标签/搜索