How to write to file in large php application(multiple questions)

append, file, flock, php

Solution

I do have high-performance, multi-threaded application, where all threads are writing (appending) to single log file. So-far did not notice any problems with that, each thread writes multiple times per second and nothing gets lost. I think just appending to huge file should be no issue. But if you want to modify already existing content, especially with concurrency - I would go with locking, otherwise big mess can happen...

Problem

What is the best way to write to files in a large php application. Lets say there are lots of writes needed per second. How is the best way to go about this. Could I just open the file and append the data. Or should i open, lock, write and unlock. What will happen of the file is worked on and other data needs to be written. Will this activity be lost, or will this be saved. and if this will be saved will is halt the application. If you have been, thank you for reading!

Original source

Related problems