獲取PHP警告錯誤信息的解決方法
更新時間:2013年06月03日 16:20:49 作者:
本篇文章是對獲取PHP警告錯誤信息的方法進行了詳細的分析介紹,需要的朋友參考下
代碼如下所示:
<?php
/**
* 更新非法字符、發(fā)送錯誤信息
*
* @author
* @copyright 2009-06-10
*/
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_error_handler('displayErrorHandler');//自定義錯誤
//調(diào)試信息
echo "time:".date("Y-m-d H:i:s")."\n";
//數(shù)據(jù)配置
//公共函數(shù)
function displayErrorHandler($error, $error_string, $filename, $line, $symbols)
{
$error_no_arr = array(1=>'ERROR', 2=>'WARNING', 4=>'PARSE', 8=>'NOTICE', 16=>'CORE_ERROR', 32=>'CORE_WARNING', 64=>'COMPILE_ERROR', 128=>'COMPILE_WARNING', 256=>'USER_ERROR', 512=>'USER_WARNING', 1024=>'USER_NOTICE', 2047=>'ALL', 2048=>'STRICT');
$msg = sprintf("%s: %s at file %s(%s)", $error_no_arr[$error] ,$error_string, $filename, $line);
if(in_array($error,array(1,2,4))){
echo $msg; echo "\n";//調(diào)試顯示
//發(fā)送信息
if($error==1||$error==2) {
sendBankMsg($error_string); //發(fā)送簡訊
if(strpos($error_string, 'xml_parse(): Bytes:')!==FALSE){
writeFiltefile($error_string);
}
}
}
}
function hex2bin($hexdata) {
$bindata = '';
for($i=0; $i < strlen($hexdata); $i += 2) {
$bindata .= chr(hexdec(substr($hexdata, $i, 2)));
}
return $bindata;
}
function writeFiltefile($error_string)
{
if(strpos($error_string, 'xml_parse(): Bytes:')===FALSE||strpos($error_string, ' 0x')===FALSE){
return;
}
//寫入文件
$filename = 'filtetext.php';
include($filename);
$error_string = str_replace('xml_parse(): Bytes:', '', $error_string);
$error_string = str_replace(' 0x','', $error_string);
$error_text = hex2bin($error_string);
$filtetextArr[] = $error_text;
$tempArr = array_unique($filtetextArr);//去除重復
$result = implode("','",$tempArr);
$result = "<?php\n\$filtetextArr = array('".$result."');\n?>";
fileWrite($filename, $result, 'w');
}
function sendBankMsg($msg)
{
$timestamp = time();
$params = "msg=".$msg
."&posttime=".$timestamp;
$length = strlen($params);
//創(chuàng)建socket連接
$domain = "www.admin.com"; //socket域名
$actionPath = "/action/bank/bankmsg.php"; //文件路徑
$fp = fsockopen($domain,80);
//構(gòu)造post請求的頭
if($fp){
$header = "POST ".$actionPath." HTTP/1.1\r\n";
$header .= "Host:".$domain."\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".$length."\r\n";
$header .= "Connection: Close\r\n\r\n";
//添加post的字符串
$header .= $params."\r\n";
//發(fā)送post的數(shù)據(jù)
fputs($fp,$header);
while (!feof($fp)) {
$line = fgets($fp,1024); //去除請求包的頭只顯示頁面的返回數(shù)據(jù)
if ($inheader && ($line == "\n" || $line == "\r\n")) {
echo $line;
}
}
fclose($fp);
}
}
function fileWrite($fFileName, $fContent, $fTag = 'w') {
ignore_user_abort (TRUE);
$fp = fopen($fFileName, $fTag);
if (flock($fp, LOCK_EX)) {
fwrite($fp, $fContent);
flock($fp, LOCK_UN);
}
fclose($fp);
ignore_user_abort (FALSE);
return;
}
?>
復制代碼 代碼如下:
<?php
/**
* 更新非法字符、發(fā)送錯誤信息
*
* @author
* @copyright 2009-06-10
*/
error_reporting(E_ERROR | E_WARNING | E_PARSE);
set_error_handler('displayErrorHandler');//自定義錯誤
//調(diào)試信息
echo "time:".date("Y-m-d H:i:s")."\n";
//數(shù)據(jù)配置
//公共函數(shù)
function displayErrorHandler($error, $error_string, $filename, $line, $symbols)
{
$error_no_arr = array(1=>'ERROR', 2=>'WARNING', 4=>'PARSE', 8=>'NOTICE', 16=>'CORE_ERROR', 32=>'CORE_WARNING', 64=>'COMPILE_ERROR', 128=>'COMPILE_WARNING', 256=>'USER_ERROR', 512=>'USER_WARNING', 1024=>'USER_NOTICE', 2047=>'ALL', 2048=>'STRICT');
$msg = sprintf("%s: %s at file %s(%s)", $error_no_arr[$error] ,$error_string, $filename, $line);
if(in_array($error,array(1,2,4))){
echo $msg; echo "\n";//調(diào)試顯示
//發(fā)送信息
if($error==1||$error==2) {
sendBankMsg($error_string); //發(fā)送簡訊
if(strpos($error_string, 'xml_parse(): Bytes:')!==FALSE){
writeFiltefile($error_string);
}
}
}
}
function hex2bin($hexdata) {
$bindata = '';
for($i=0; $i < strlen($hexdata); $i += 2) {
$bindata .= chr(hexdec(substr($hexdata, $i, 2)));
}
return $bindata;
}
function writeFiltefile($error_string)
{
if(strpos($error_string, 'xml_parse(): Bytes:')===FALSE||strpos($error_string, ' 0x')===FALSE){
return;
}
//寫入文件
$filename = 'filtetext.php';
include($filename);
$error_string = str_replace('xml_parse(): Bytes:', '', $error_string);
$error_string = str_replace(' 0x','', $error_string);
$error_text = hex2bin($error_string);
$filtetextArr[] = $error_text;
$tempArr = array_unique($filtetextArr);//去除重復
$result = implode("','",$tempArr);
$result = "<?php\n\$filtetextArr = array('".$result."');\n?>";
fileWrite($filename, $result, 'w');
}
function sendBankMsg($msg)
{
$timestamp = time();
$params = "msg=".$msg
."&posttime=".$timestamp;
$length = strlen($params);
//創(chuàng)建socket連接
$domain = "www.admin.com"; //socket域名
$actionPath = "/action/bank/bankmsg.php"; //文件路徑
$fp = fsockopen($domain,80);
//構(gòu)造post請求的頭
if($fp){
$header = "POST ".$actionPath." HTTP/1.1\r\n";
$header .= "Host:".$domain."\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".$length."\r\n";
$header .= "Connection: Close\r\n\r\n";
//添加post的字符串
$header .= $params."\r\n";
//發(fā)送post的數(shù)據(jù)
fputs($fp,$header);
while (!feof($fp)) {
$line = fgets($fp,1024); //去除請求包的頭只顯示頁面的返回數(shù)據(jù)
if ($inheader && ($line == "\n" || $line == "\r\n")) {
echo $line;
}
}
fclose($fp);
}
}
function fileWrite($fFileName, $fContent, $fTag = 'w') {
ignore_user_abort (TRUE);
$fp = fopen($fFileName, $fTag);
if (flock($fp, LOCK_EX)) {
fwrite($fp, $fContent);
flock($fp, LOCK_UN);
}
fclose($fp);
ignore_user_abort (FALSE);
return;
}
?>
相關(guān)文章
PHP+Redis鏈表解決高并發(fā)下商品超賣問題(實現(xiàn)原理及步驟)
這篇文章主要介紹了PHP+Redis鏈表解決高并發(fā)下商品超賣問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-08-08在Laravel的Model層做數(shù)據(jù)緩存的實現(xiàn)
這篇文章主要介紹了在Laravel的Model層做數(shù)據(jù)緩存的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-09-09微信公眾平臺網(wǎng)頁授權(quán)獲取用戶基本信息中授權(quán)回調(diào)域名設置的變動
這篇文章主要介紹了微信公眾平臺網(wǎng)頁授權(quán)獲取用戶基本信息中授權(quán)回調(diào)域名設置的變動,需要的朋友可以參考下2014-10-10PHP中trait的使用和同時引入多個trait時同名方法沖突的處理方法
這篇文章主要介紹了PHP中trait的使用和同時引入多個trait時同名方法沖突的處理,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-04-04php在windows環(huán)境下獲得cpu內(nèi)存實時使用率(推薦)
這篇文章主要介紹了php在windows環(huán)境下獲得 cpu 內(nèi)存實時使用率的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2018-02-02