Download the PHP package netsket/sf-doctrine-master-slave-plugin without Composer

On this page you can find all versions of the php package netsket/sf-doctrine-master-slave-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sf-doctrine-master-slave-plugin

The sfDoctrineMasterSlavePlugin plugin manages database connections and directs queries to the appropriate connection: either the master or a slave database.

Once the plugin is enabled you can mark a connection as the master connection in databases.yml by using the string "master" in its name:

all:
  master:
    class: sfDoctrineDatabase
    param:
      dsn:      mysql:dbname=database;host:master.example.com
      username: root
      password: ~
  slave:
    class: sfDoctrineDatabase
    param:
      dsn:      mysql:dbname=database;host:slave.example.com
      username: root
      password: ~

Alternatively, you can provide an is_master parameter in the configuration:

all:
  doctrine:
    class: sfDoctrineDatabase
    param:
      dsn:       mysql:dbname=database;host:master.example.com
      username:  root
      password:  ~
      is_master: true

If no connection is marked as the master connection using either of these techniques, the first connection configured first will be used. If multiple connections are marked as master, only the last connection marked will be used as the master connection; the others will be used as slaves.

If your configuration includes more than one slave database, the plugin will select one of them at random to use for the duration of the request.

Accessing the right connection

You can access the master or slave connections from the configuration object:

[php]
ProjectConfiguration::getActive()->getMasterConnection();
ProjectConfiguration::getActive()->getSlaveConnection();

The plugin interacts with Doctrine as your database connection objects are created and updates the current connection set in the Doctrine_Manager to be the master connection. This way, any calls to Doctrine_Manager::connection() will return the master connection, which is usually what you need when calling that method (i.e. when beginning a transaction).

NOTE The slave database accessor ->getSlaveConnection() includes logic to check whether the master database has any open transactions, and will return the master connection in that case.

Choosing from multiple slaves

If you have multiple slave connections configured in databases.yml, the plugin will choose one at random to use for the duration of the current request. If you want to customize the logic surrounding how a slave connection is selected, you can do so by listening to the doctrine.select_slave event.

/** Listens to the doctrine.select_slave event. */
public function selectSlave(sfEvent $event)
{
  if (in_array('slave1', $event['slaves]))
  {
    $event->setReturnValue('slave1');
    return true;
  }
}

The doctrine.select_slave event includes the following parameters:

Notice this event receives the names of connections as parameters, not the connection objects themselves. You can access the connection objects in your event listener by calling Doctrine_Manager::getInstance()->getConnection($name).

Connecting to multiple schemas

If your schema assigns different connections to different models, you will need to organize the master and slave connections for each of these schema into groups using the group parameter:

all:
  # db1 connections
  db1_master:
    class: sfDoctrineDatabase
    param:
      dsn:      mysql:dbname=db1;host:db1-master.example.com
      username: root
      password: ~
      group:    db1
  db1_slave:
    class: sfDoctrineDatabase
    param:
      dsn:      mysql:dbname=db1;host:db1-slave.example.com
      username: root
      password: ~
      group:    db1

  # db2 connections
  db2_master:
    class: sfDoctrineDatabase
    param:
      dsn:      mysql:dbname=db2;host:db2-master.example.com
      username: root
      password: ~
      group:    db2
  db2_slave:
    class: sfDoctrineDatabase
    param:
      dsn:      mysql:dbname=db2;host:db2-slave.example.com
      username: root
      password: ~
      group:    db2

Emulating read-only connections

It's important to be able to test whether your connection management is working correctly even when you're not connecting to any read-only databases. The plugin provides a connection listener that emulates a read-only connection for this purpose. Setup distinct master and slave connections in databases.yml to enable this emulation in debug and test modes.

dev:
  master: &master
    class: sfDoctrineDatabase
    param:
      dsn:       mysql:dbname=database;host=localhost
      username:  root
      password:  ~
  slave: *master

All versions of sf-doctrine-master-slave-plugin with dependencies

PHP Build Version
Package Version
Requires composer/installers Version ~1.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package netsket/sf-doctrine-master-slave-plugin contains the following files

Loading the files please wait ....