The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Is TimestampLogFileWriter thread safe?

jorgeas80's Avatar


07 Jun, 2012 11:19 AM


I'm using TimestampLogFileWriter in Slim 1.6.0 to log my messages to a log file. My question is: is this writer thread safe? I guess it totally relies on fwrite. So my question should be: is fwrite thread safe? I think I should use flock, but not sure.

Going further: my Slim-based app is called by a lot of mobile-platform-based clients, and I'd like to log them all. Should I use this approach, with a log file, or a database log is a better idea?

Many thanks in advance, and best regards

  1. 1 Posted by jorgeas80 on 07 Jun, 2012 11:24 AM

    jorgeas80's Avatar

    Forgot to say I'm using Apache 2.2.20. Regular installation from Ubuntu 11.10 (apt-get install)

  2. Support Staff 2 Posted by Brian Nesbitt on 03 Jul, 2012 03:19 AM

    Brian Nesbitt's Avatar

    According to the PHP manual for fwrite it says:

    If handle was fopen()ed in append mode, fwrite()s are atomic (unless the size of string
    exceeds the filesystem's block size, on some platforms, and as long as the file is on a
    local filesystem). That is, there is no need to flock() a resource before calling fwrite();
    all of the data will be written without interruption.

    The default for ubuntu seems to be a file block size of 4096. So unless you are writing really long log messages or you modified the block size when formatting the disk you should be ok.

    Saying that though, if the site is going to receive any type of decent traffic then a file log may not be the right answer.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac