mysql - How to configure PHP PDO to connect to a multimaster cluster? -


i using percona xtradb cluster load-balance database.

the usual approach connect database is:

$db = new \pdo('mysql:dbname=foo;host=127.0.0.1'); 

however, there multiple master, each of may possibly dead @ point in time.

how establish connection database cluster load-balancing , safe fail-over?

my intuitive guess simple as:

<?php $cluster = ['10.128.155.150', '10.128.155.151', '10.128.155.152'];  shuffle($cluster);  foreach ($cluster $i => $ip) {     try {         $db = new \pdo('mysql:dbname=foo;host=' . $ip . ';charset=utf8');          break;     } catch (\pdoexception $e) {         if ($i === count($cluster)) {             throw $e;         }     } } 

though, know if there more bullet-proof solutions developed.

edit 2013 may 3, 14:42. explained approach bad because user need wait until connection timesout. right tool job http://us1.php.net/manual/en/intro.mysqlnd-mux.php.

beware though, that:

the proof-of-concept not support unbuffered queries, prepared statements, , asynchronous queries.

edit 2013 may 3, 20:38. ended looking @ heartbeat , haproxy.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -