PHP中设置时区,记录日志文件的实现代码
程序员文章站
2022-06-29 21:30:40
复制代码 代码如下:
<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>
原文网址:http://txw1958.cnblogs.com/
复制代码 代码如下:
<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>
原文网址:http://txw1958.cnblogs.com/
上一篇: 实时同步sersync实战
下一篇: 原生JS实现列表内容自动向上滚动效果