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.

Link to comment
Share on other sites

Yes they'll queue up.  That may cause big problems if you have too many people trying to write to the file!  So you should keep an eye on it at peak times to make sure the queue of waiting scripts is emptying fast enough.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.