Copyright 1997-2012 the PHP Documentation Group.
The built-in read-write-split mechanism is very basic. Every query
which starts with SELECT is considered a read
request to be sent to a MySQL slave server. All other queries
(such as SHOW statements) are considered as
write requests that are sent to the MySQL master server. The
build-in behavior can be overruled using
SQL hints, or
a user-defined
callback
function.
The read-write splitter is not aware of multi-statements.
Multi-statements are considered as one statement. The decision of
where to run the statement will be based on the beginning of the
statement string. For example, if using
mysqli_multi_query
to execute the multi-statement SELECT id FROM test ;
INSERT INTO test(id) VALUES (1), the statement will be
redirected to a slave server because it begins with
SELECT. The INSERT
statement, which is also part of the multi-statement, will not be
redirected to a master server.
Applications must be aware of the consequences of connection switches that are performed for load balancing purposes. Please check the documentation on connection pooling and switching, transaction handling, failover load balancing and read-write splitting.

User Comments
Add your own comment.