In this part of Mysql-nd manual is described how to implement recommended way of failing over when loosing connection to slave MySQL server.
I'am willing to implement it in PhalconPHP. As I have couple of important projects using Phalcon and Mysql-nd, it is really important for me to do it in right place.
Trying to find some documentation, but can't find any example to even start with. Was trying to find EventManager approach, looking into Phalcon Documentation here and here but can't find way to do it transparently.
Most attractive way would be to use event manager to capture error event and query the same again if connection error.
1 UPDATE
After reading some Phalcon sources I found, that there may be no way to run same query second time in standard way - I mean here via some kind of PDO parameter or using Phalcons' EventManager
attached to db
service. One possible attempt I found is to actually run any query after db:afterConnection
event, but it is not a solution.
2 UPDATE
db:afterConnection
is hardly reachable, instead it is possible to gather everything during db:beforeQuery
. Problem is, that PDO is run by Phalcon with PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
, so when connection to slave dies it can't reach db:afterConnection
event. It is possible to obtain PDO instance during db:beforeQuery
and change this attribute via EventManager
, but it gives nothing, because even if I am able to send same query second time, I can't find a way to return it in proper place (cannot override query result during db:afterQuery
) because obtained statement is not a part of event send, and Eventmanager result is not being used at all:
if typeof statement == "object" {
if typeof eventsManager == "object" {
eventsManager->fire("db:afterQuery", this, bindParams);
}
return new ResultPdo(this, statement, sqlStatement, bindParams, bindTypes);
}