PHP中設(shè)置時區(qū),記錄日志文件的實現(xiàn)代碼
更新時間:2013年01月07日 15:04:57 作者:
php中設(shè)置時區(qū) 記錄日志文件的實現(xiàn)代碼,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
<html>
<body>
<?php
date_default_timezone_set('Asia/Hong_Kong'); //set time zone
set_error_handler("myHandler"); //set error handler
$chinatime = date('Y-m-d H:i:s'); //get current time
$max_size = 500000;
try
{
$content = "Hello WeiXin!";
logger2($content);
//throw new Exception("Value must be 1 or below aaaaaaaaaaaaaaaaaaa");
}
catch(Exception $e)
{
logger2("Exception Message: ".$e->getMessage());
}
//record operation log into .log file
function logger($log_content)
{
print_r(date('H:i:s')." ".$log_content."<br />");
$log_filename = date("Ymd").".log";
$file = fopen($log_filename ,"a+");
fwrite($file, date('H:i:s')." ".$log_content."\r\n");
fclose($file);
}
//record operation log into .log file
function logger2($log_content)
{
Global $max_size;
print_r(date('H:i:s')." ".$log_content." "."<br />");
$log_filename = date("Ymd").".log";
if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);sleep(1);}
file_put_contents($log_filename, date('H:i:s')." ".$log_content." "."\r\n", FILE_APPEND);
}
//error handler function
function myHandler($level, $message, $file, $line, $context)
{
logger("<b>[ERROR]</b> LEVEL: $level, MESSAGE: $message, FILE: $file, LINE: $line, CONTENT: $context");
die();
}
?>
</body>
</html>
原文網(wǎng)址:http://txw1958.cnblogs.com/
您可能感興趣的文章:
- 關(guān)于php程序報date()警告的處理(date_default_timezone_set)
- PHP中設(shè)置時區(qū)方法小結(jié)
- PHP跨時區(qū)(UTC時間)應(yīng)用解決方案
- PHP中遇到的時區(qū)問題解決方法
- PHP獲取中國時間(上海時區(qū)時間)及美國時間的方法
- php時區(qū)轉(zhuǎn)換轉(zhuǎn)換函數(shù)
- php輸出全球各個時區(qū)列表的方法
- 有關(guān) PHP 和 MySQL 時區(qū)的一點總結(jié)
- PHP應(yīng)用跨時區(qū)功能的實現(xiàn)方法
- PHP date_default_timezone_set()設(shè)置時區(qū)操作實例分析
相關(guān)文章
Laravel模板引擎Blade中section的一些標(biāo)簽的區(qū)別介紹
這篇文章主要介紹了Laravel模板引擎Blade中section的一些標(biāo)簽的區(qū)別介紹,本文講解了@yield 與 @section、@show 與 @stop、@append 和 @override的區(qū)別,需要的朋友可以參考下2015-02-02php的mail函數(shù)發(fā)送UTF-8編碼中文郵件時標(biāo)題亂碼的解決辦法
這篇文章主要介紹了php的mail函數(shù)發(fā)送UTF-8編碼中文郵件時標(biāo)題亂碼的解決辦法,需要的朋友可以參考下2015-10-10