Jump to content

Lots of people writing to one file


thiggins09

Recommended Posts

Yes, the problem is well known.  There are a few solutions.

 

1.  http://sg.php.net/manual/en/function.flock.php

2.  Notice this in the notes for fwrite():

Note:  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.

 

If you're writing to an nfs mounted filesystem though, you may have trouble.

 

To answer your second question, no, any number of scripts can open the same file unless you lock it.

Hi, I have a file that is read, then modified, then the stream is opened to be written to and written to. When multiple users are accessing this file, sometimes it disregards the others edit and messes up the file. How can this be fixed?

 

Maybe you should consider a small database like SQLite to work with. This should be okey and it could solve all your problems.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.