Set the time zone in PHP and record the log file implementation code _ PHP Tutorial

Source: Internet
Author: User
Set the time zone in PHP to record the implementation code of the log file. The copy code is as follows: htmlbody? Phpdate_default_timezone_set (AsiaHong_Kong); settimezoneset_error_handler (myHandler); seterrorhandler $ chinatimedate (Y-m-d The code is as follows:




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 aaaaaaaaaaaaaaaaa ");
}
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 ."
");
$ 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 .""."
");
$ 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 ("[ERROR]LEVEL: $ level, MESSAGE: $ message, FILE: $ file, LINE: $ line, CONTENT: $ context ");
Die ();
}
?>



Http://txw1958.cnblogs.com/

The http://www.bkjia.com/PHPjc/326379.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326379.htmlTechArticle code is as follows: 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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.