PHP set time zone, log file implementation code _php tips

Source: Internet
Author: User
Tags set time
Copy Code code as follows:

<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>

Original website: http://txw1958.cnblogs.com/

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.