Using database replication with Pressflow 5 and 6
Configuring settings.php
For an unnamed master connection and a single slave database
$db_url = 'mysqli://user:password@master-host/database'; $db_slave_url = 'mysqli://user:password@slave-host/database';
For an unnamed master connection and multiple slave databases
When multiple slave databases are available, Pressflow randomly picks one to use for each request.
$db_url = 'mysqli://user:password@master-host/database'; $db_slave_url = array(); $db_slave_url[] = 'mysqli://user:password@slave-host-1/database'; $db_slave_url[] = 'mysqli://user:password@slave-host-2/database';
For a named master connection and a single slave database
Slave databases can also be configured for the non-default connection, but they're unlikely to be used.
$db_url = array(); $db_url['default'] = 'mysqli://user:password@master-host/database'; $db_url['another'] = 'mysqli://user:password@another-host/another-database'; $db_slave_url = array(); $db_slave_url['default'] = 'mysqli://user:password@slave-host/database';
For a named master connection and multiple slave databases
$db_url = array(); $db_url['default'] = 'mysqli://user:password@master-host/database'; $db_url['another'] = 'mysqli://user:password@another-host/database'; $db_slave_url = array(); $db_slave_url['default'] = array(); $db_slave_url['default'][] 'mysqli://user:password@slave-host-1/database'; $db_slave_url['default'][] 'mysqli://user:password@slave-host-2/database';
Using the Cookie Cache Bypass module
The Cookie Cache Bypass module allows anonymous users who have submitted forms to bypass reverse proxy caches and database replication to get fresh pages, presumably containing results of their form postings. This module works by adding an additional #submit
handler to all form submissions that generates a short-lived cookie. This cookie persists long enough that, by the time of its expiration, slave databases and reverse proxy caches should be updated with that user's action.
Use of this module is important in situations that use reverse proxy caching or database replication in combination with anonymous user activity. Without this module enabled, anonymous users may post comments but be unable to immediately see their work. This causes frustration and unnecessary resubmission.
API: Sending queries to the slave servers
Pressflow's replication functionality add two main functions to the API and modifies a third.
db_query_slave
- This function is parameter-equivalent to
db_query
, but should only be used withSELECT
queries that operate properly with slightly stale data.
- This function is parameter-equivalent to
db_query_range_slave
- This function is parameter-equivalent to
db_query_range
with the same caveats asdb_query_slave
.
- This function is parameter-equivalent to
pager_query
- Paginated queries are always sent to the slave(s).