PHISON-UP10 Production tool v1.78.00 PHP write text log implementation code

Source: Internet
Author: User
Tags php write
Copy CodeThe code is as follows:


**
* Write files
* @param string $file file path
* Write content @param string $str
* @param char $mode write mode
*/
function WriteFile ($file, $str, $mode = ' W ')
{
$oldmask = @umask (0);
$fp = @fopen ($file, $mode);
@flock ($FP, 3);
if (! $fp)
{
Return false;
}
Else
{
@fwrite ($fp, $STR);
@fclose ($FP);
@umask ($oldmask);
Return true;
}
}


Extending the app, such as logging the URL content of each request

Copy the Code code as follows:


function Writegeturlinfo ()
{
Get the requester's address, client, requested page, and parameters
$requestInformation = $_server[' remote_addr ']. ', '. $_server[' http_user_agent ']. ', ' http://'. $_server[' Http_host '. Htmlentities ($_server[' php_self '). $_server[' query_string ']. " \ n ";
$fileName = RootPath. ' /log/'. Date (' y-m-d '). Log '; The site root directory RootPath is in the configuration file define (' RootPath ', substr (dirname (__file__)));
WriteFile ($fileName, $requestInformation, ' a '); Represents an Append
}


With File_put_contents ($filename, $data, file_append); better

The above describes the PHISON-UP10 production tool v1.78.00 PHP write text log implementation code, including the PHISON-UP10 production tools v1.78.00 aspects of the content, I hope to be interested in PHP tutorial friends helpful.

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