Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    74
    Thanks
    0
    Thanked 1 Time in 1 Post

    Question How to add a Timestamp to fwrite logging to disk? [PHP5]

    I am currently using fwrite(...) to log traces to a log file, seems to be working like a charm - but now I would like to beef it up a little.
    Instead of simply having the error messages, I wanted to add a TimeStamp to the head of the string, making it easier to find out when the issue occured.

    Currently I have the following
    Code:
    if (fwrite($this->hFile, $string."\r\n")) return true;
    How can I add a timestamp to this in PHP5?
    Thanks,

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Shaitan00 View Post
    I am currently using fwrite(...) to log traces to a log file, seems to be working like a charm - but now I would like to beef it up a little.
    Instead of simply having the error messages, I wanted to add a TimeStamp to the head of the string, making it easier to find out when the issue occured.

    Currently I have the following
    Code:
    if (fwrite($this->hFile, $string."\r\n")) return true;
    How can I add a timestamp to this in PHP5?
    Thanks,
    you can use time():

    http://www.php.net/manual/en/function.time.php

    best regards

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Create a variable that contains the current date and time, then just concatenate it to $string. You can use php's date() function for this.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •