Synopsis: new Swift_Connection_Rotator( [array connections] )
Much like the Multi connection, the Rotator connection also provides redundancy. However, in addition it also provides a fairly unintelligent way to load balance between connections.
You provide it with a collection of different connections (possibly including some other rotating ones if you're crazy enough to do so ;)) and it tries each one in turn until one works, the rest are marked as “dead” internally and will not be retried. Upon sending an email with Swift, the connection will rotated to the next one in sequence so the subsequent email will be sent through a different server.
This is not as expensive as it may sound. Once a connection has been established, it is kept open persistently until you call the disconnect() method in the Swift class. Connections are not all opened unless they are needed neither (i.e. they open when the connection rotates if they are not already open, not upon instantiation), therefore, if you provide a lot of connections it's possible that some of them will never even be tried.
Internally, a plugin is used to invoke the rotation. The plugin used is Swift_Plugin_ConnectionRotator and simply listens for sendEvents being dispatched by Swift. You don't really need to worry about this, but if it's of any use the plugin is automatically registered in Swift with the ID “_ROTATOR”.
Like with the Multi connection, this connection either takes an array of connections in the constructor, or uses the addConnection() method to populate it.
require_once "lib/Swift.php"; require_once "lib/Swift/Connection/Rotator.php"; require_once "lib/Swift/Connection/SMTP.php"; //Populate an array if you want to provide connections at instantiation $connections = array(); $conn1 =& new Swift_Connection_SMTP("smtp.host1.tld"); $conn1->setUsername("user"); $conn1->setPassword("pass"); $connections[] =& $conn1; $conn2 =& new Swift_Connection_SMTP("smtp.host2.tld"); $connections[] =& $conn2; //Start swift as normal $swift =& new Swift(new Swift_Connection_Rotator($connections)); //Do some stuff $swift->send(new Swift_Message("Subject", "Body"), "foo@bar.com", "me@home.tld"); //Feel free to throw in new connections at run-time $swift->connection->addConnection(new Swift_Connection_SMTP("smtp.host3.tld"));