Databases, Frameworks, PHP

Solar Framework: MySQL Replication Adapter

As part of the Solar-1.0.0alpha2 release, Paul M. Jones included an SQL adapter that lets you connect to master/slave MySQL installations.


Replication enables data from one MySQL database server (called the master) to be replicated to one or more MySQL database servers (slaves). Replication is asynchronous – your replication slaves do not need to be connected permanently to receive updates from the master, which means that updates can occur over long-distance connections and even temporary solutions such as a dial-up service. Depending on the configuration, you can replicate all databases, selected databases, or even selected tables within a data.

Solar Adapter

When you get into a situation where you need to scale up, you might need a replicated MySQL database setup. In such cases, there is one “master” server that handles reads and writes, and there are one or more “slave” servers that are read-only. This means you need to pick which server you’re going to connect to based on the kind of statement you need to issue (SELECT, INSERT, UPDATE, etc).

The Solar_Sql_Adapter_MysqlReplicated adapter handles all the connections and switching-around for you, and you don’t need change a single line of application code. All you need to do is modify your configuration file to tell it where your master and slave servers are.

More: Adapter for Master/Slave MySQL Setups

Related Links

6 thoughts on “Solar Framework: MySQL Replication Adapter

  1. this is actually how we started off our database code, but then quickly reverted back to manually picking the appropriate database for our code…

    Slowly but surely we might be able to get back to a point where we can intelligently pick the master or slave based on the query. Its bad, because ever so often you need to do a write based on an earlier read.

    So there was the option to opt-out for getting the slave automatically, but for our application I pushed for opt-in, because I prefer clarity over automagic behaviour.

    So I would say conclusively, avoid this!

  2. Interestingly that comment was also posted on the solarphp blog. It makes me feel that it was written by someone just venturing into mysql replication, and hasn’t faced a lot of real-life situations yet =)

  3. I agree, it’s simple and doesn’t cover all the use cases (partitioning data, failover, etc). But it’s a good start.

  4. Hi Federico, Evert —

    Granted, the Solar adapter is a basic starting point. If you know of public PHP code examples of how replication is handled in other systems, I’d be very happy hear about them, so I can review to see how I can incorporate their lessons.

  5. Hi Paul,

    I think what you are doing is great and I’m sure it’s going to inspire other PHP projects, including the Zend Framework.

    I’ve been following Simon’s discussion about multiple database support. Here are the requirements and problems they are trying to solve.

    (There are some interesting links at the bottom of that page)

    In PHP, the only replicated adapter I’m aware of is HyperDB, the one that WordPress uses.

  6. Pingback: Carrero

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s