Posts: 24
Name: Nick Cousins
Location: Northern Ireland
|
I had a similar quandry.
For the past 8 months I've been working on a business directory website.
I was on a pretty low budget, and I decided that 3 separate cPanel hosts, and one reliable vServer host (as a load-balancer) was the best way to go.
So the website has been backed up nightly across the three webservers using a nifty little program I found on the net.
The problem I had was that the database behind the whole thing, which is growing quite rapidly, was located on just one server - and if this server went down - all the backup webservers couldn't access the data so the site was useless anyway!
So after all these months I sat down and wrote a little PHP script (which I'm currently still messing with) which acts as middleware between the website and the database.
It replaces the main mysql functions in PHP (such as mysql_query and mysql_fetch_array etc...) with it's own variants.
The idea is that it holds details on database servers on all three web servers (ie each webserver has its own MySQL server).
When I do a select query (or similar) the script sends it to it's own MySQL database. If that is unavailable, it will try all of the other databases until it finds one which is available.
The other issue (relating to your backup question) was how often do I sync all of these databases, and how?
So I have built into this script a little decision maker which analyses my MySQL query, and if it finds an update, insert or delete query, it sends it to all of the database servers in turn, and sends me back a status flag for each server as an array.
Currently the three functions it can handle are:
mysql_query
mysql_num_rows
mysql_fetch_array
I was thinking of making it open-source if anyone's interested in it, but I'd love to hear your ideas (or tell me I'm reinventing the wheel!).
I know that MySQL has built-in replication but I don't have the budget to go for a dedicated MySQL server so I need to find the best way around it I can!
|