0

I have a web server that host several PHP applications and I want to know if its possible to encounter a write conflict under heavy normal/traffic when writing log details to a text file. In my case all applications using the same log file. If the possibility is high please give advises on how it could be reduced or avoided.

If you going to down vote, give reasons.

Markel Mairs
  • 742
  • 2
  • 10
  • 28

1 Answers1

3

To avoid any issues you need to lock the file so only one application at a time is writing to the file. With no exceptions - you need to have a lock.

If you have really loaded application(s) - you could choose some non-blocking logging daemon or storage

zerkms
  • 249,484
  • 69
  • 436
  • 539
  • Just curious, I thought for at least Apache2, its serves one at a time? If the first user is on a stall (long run time), the second user visits during the stall period is affected as well until the first user is freed. I do not disagree with your statement though. – Matt Lo Jan 23 '12 at 03:55
  • @Matt Lo: apache can serve a lot of simultaneous requests, otherwise no one would use it. – zerkms Jan 23 '12 at 03:56
  • 1
    I agree whole-heartedly with this answer. That said, [this post](http://stackoverflow.com/questions/3832646/what-happens-in-nfs-if-2-or-more-servers-try-to-write-the-same-file-simultaneous) mentions the possibility that if the file was opened in append mode, no lock may be necessary. Locking, however, is still a good idea (at the expense of a minor performance hit). – Jonah Bishop Jan 23 '12 at 04:01
  • @ zerkms I dont know much about daemon or system processes but your answer sounds reasonable good. Thanks – Markel Mairs Jan 23 '12 at 04:02
  • @Tobi: in general you could choose between some UDP-based network daemons. It is a common solution. Cannot recommend any particular one, but you could google it - there must be a lot of them – zerkms Jan 23 '12 at 04:04
  • @ Jonah Bishop, about your link. Am not on Linux. Am running the stuff on windows server. – Markel Mairs Jan 23 '12 at 04:15