in reply to Writing to a log file without colliding

What you're looking for is flock. Take a look at how merlyn implements a hit counter CGI script to see how to safely employ it.

Makeshifts last the longest.

  • Comment on Re: Writing to a log file without colliding

Replies are listed 'Best First'.
Re^2: Writing to a log file without colliding
by cgraf (Beadle) on Aug 17, 2004 at 10:22 UTC
    My concern with using an exclusive lock is that the other processes needing to write will block/wait until the file becomes available, with will affect performance.

      There is no way around locking for a concurrently written logfile. If that is a problem, use a database.

      Makeshifts last the longest.

        here is no way around locking for a concurrently written logfile.
        Yes there is. If the file is opened for appending ('>>') and a single string is written using syswrite, then the string is guaranteed to be atomicly appended to the file. Well, on UNIX systems anyway.

        Dave.