Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In PHP we're creating various files on our servers. The problem is we have two servers, which are load balanced. What would be the best way to keep the created files in sync between the two? Is there some common practice I've just never heard of?

share|improve this question
up vote 2 down vote accepted

#1: You can let the OS do the work. Assuming you are using Microsoft Windows environment, a DFS would be the simplest solution (in terms of administrative work). You have to set up a Domain Controller, which needs an R2 version of the Windows Server (be it 2003 or 2008).

#2: Don't create files on load balanced servers' own HDD. You should separate file-handling from the webserver and use an external storage.

share|improve this answer
What do you think is in Win2k8 R2 that's not in Win2k8? – uSlackr May 5 '11 at 1:14
ie. replication groups. – karatedog May 16 '11 at 20:57

Shared storage is the way to go. We use NAS to make the files available to all servers.

share|improve this answer

Well, a one way sync would be easy with rsync. What about bi-directional? I did a quick google and it seems it's possible.

At the bottom of that link it gives you a method.

share|improve this answer
Be aware that there will be a delay. So if you create files on one server, there will be a delay before they end up on the other one. That may have a negative impact on your system, or it may be an acceptable tradeoff. – Matt H May 4 '11 at 22:27

Your load balancer should allow you to configure it so that all requests from one particular client will always go to the same load-balanced server. With this turned on, any time a file is created for a client, it's there on subsequent requests from that same client. Doesn't work so well, though, if e.g. Client A is triggering the creation of a file for Client B.

You may want to consider a database server. For example, if your created files are storing session information, store that data in a database instead, which both web servers point to (you could add replication here to keep load distributed if you'd like/need). If it's not session data, consider storing the data necessary to generate the files in this database, and only generate the actual file on-demand when requested by pulling this data from the database; might not be applicable in your situation, though.

Finally, you could consider shared and/or replicated storage. DFS in a Windows environment is a good replication solution; NFS or SMB might be applicable, or a SAN; basically everything @karatedog mentioned.

One more option to consider is a file-centric database solution, such as MongoDB, which basically takes the form of a database serving as a centralized file store. Put your files there, and either server can pull them back out again later.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.