I know file_put_contents() makes it really easy to append data to a file in PHP. I’d like to try using PHP “threads” to file_put_contents() to the same log file from different PHP threads. Is there a risk in running file_put_contents() on the same file from different PHP threads or will these threads happily block if the file is locked or being accessed by another thread?
EDIT: Found a similar question that recommends flock(), but the risk question does not seem to be fully addressed. Are these “atomic” write operations?
as it says on the man page (that you gave a link for!):
Use the
LOCK_EXflag to prevent double writes