Einführung
The mysqlnd replication and load balancing plugin (mysqlnd_ms) adds easy to use MySQL replication support to all PHP MySQL extensions that use mysqlnd.
As of version PHP 5.3.3 the MySQL native driver for PHP (mysqlnd) features an internal plugin C API. C plugins, such as the replication and load balancing plugin, can extend the functionality of mysqlnd.
The MySQL native driver for PHP is a C library that ships together with PHP as of PHP 5.3.0. It serves as a drop-in replacement for the MySQL Client Library (libmysqlclient). Using mysqlnd has several advantages: no extra downloads are required because it's bundled with PHP, it's under the PHP license, there is lower memory consumption in certain cases, and it contains new functionality such as asynchronous queries.
Mysqlnd plugins like mysqlnd_ms operate, for the most part, transparently from a user perspective. The replication and load balancing plugin supports all PHP applications, and all MySQL PHP extensions. It does not change existing APIs. Therefore, it can easily be used with existing PHP applications.
Key Features
The key features of PECL/mysqlnd_ms are as follows.
-
Transparent and therefore easy to use.
-
Supports all of the PHP MySQL extensions.
-
SSL support.
-
A consistent API.
-
Little to no application changes required, dependent on the required usage scenario.
-
Lazy connections: connections to master and slave servers are not opened before a SQL statement is executed.
-
Optional: automatic use of master after the first write in a web request, to lower the possible impact of replication lag.
-
-
Can be used with any MySQL clustering solution.
-
MySQL Replication: Read-write splitting is done by the plugin. Primary focus of the plugin.
-
MySQL Cluster: Read-write splitting can be disabled. Configuration of multiple masters possible
-
Third-party solutions: the plugin is optimized for MySQL Replication but can be used with any other kind of MySQL clustering solution.
-
-
Featured read-write split strategies
-
Automatic detection of SELECT.
-
Supports SQL hints to overrule automatism.
-
User-defined.
-
Can be disabled for, for example, when using synchronous clusters such as MySQL Cluster.
-
-
Featured load balancing strategies
-
Round Robin: choose a different slave in round-robin fashion for every slave request.
-
Random: choose a random slave for every slave request.
-
Random once (sticky): choose a random slave once to run all slave requests for the duration of a web request.
-
User-defined. The application can register callbacks with mysqlnd_ms.
-
PHP 5.4.0 or newer: transaction aware when using API calls only to control transactions.
-
Weighted load balancing: servers can be assigned different priorities, for example, to direct more requests to a powerful machine than to another less powerful machine. Or, to prefer nearby machines to reduce latency.
-
-
Global transaction ID
-
Client-side emulation. Makes manual master server failover and slave promotion easier with asynchronous clusters, such as MySQL Replication.
-
Support for built-in global transaction identifier feature of MySQL 5.6.5 or newer.
-
Supports using transaction ids to identify up-to-date asynchronous slaves for reading when session consistency is required. Please, note the restrictions mentioned in the manual.
-
Throttling: optionally, the plugin can wait for a slave to become "synchronous" before continuing.
-
-
Service and consistency levels
-
Applications can request eventual, session and strong consistency service levels for connections. Appropriate cluster nodes will be searched automatically.
-
Eventual consistent MySQL Replication slave accesses can be replaced with fast local cache accesses transparently to reduce server load.
-
-
Partitioning and sharding
-
Servers of a replication cluster can be organized into groups. SQL hints can be used to manually direct queries to a specific group. Grouping can be used to partition (shard) the data, or to cure the issue of hotspots with updates.
-
MySQL Replication filters are supported through the table filter.
-
-
MySQL Fabric
-
Experimental support for MySQL Fabric is included.
-
Limitations
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.
Hinweis:
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 und read-write splitting.
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 30/01/2003, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/php-rf-intro.mysqlnd-ms.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.