Copyright 1997-2012 the PHP Documentation Group.
Copyright 1997-2012 the PHP Documentation Group.
mysqlnd_memcache_get_config
Returns information about the plugin configuration
Description
array mysqlnd_memcache_get_config(mixed connection);
This function returns an array of all mysqlnd_memcache related
configuration information that is attached to the MySQL
connection. This includes MySQL, the Memcache object provided
via
mysqlnd_memcache_set,
and the table mapping configuration that was automatically
collected from the MySQL Server.
Parameters
Return Values
An array of mysqlnd_memcache configuration information on
success, otherwise
FALSE
.
The returned array has these elements:
Table 22.81. mysqlnd_memcache_get_config
array structure
| Array Key | Description |
|---|---|
| memcached | Instance of Memcached associated to this MySQL connection by
mysqlnd_memcache_set.
You can use this to change settings of the memcache
connection, or directly by querying the server on this
connection. |
| pattern | The PCRE regular expression used to match the SQL query sent to the
server. Queries matching this pattern will be further
analyzed to decide whether the query can be
intercepted and sent via the memcache interface or
whether the query is sent using the general MySQL
protocol to the server. The pattern is either the
default pattern
(MYSQLND_MEMCACHE_DEFAULT_REGEXP)
or it is set via
mysqlnd_memcache_set. |
| mappings | An associative array with a list of all configured containers as they
were discovered by this plugin. The key for these
elements is the name of the container in the MySQL
configuration. The value is described below. The
contents of this field is created by querying the
MySQL Server during association to MySQL and a
memcache connection using
mysqlnd_memcache_set. |
| mapping_query | An SQL query used during
mysqlnd_memcache_set
to identify the available containers and mappings. The
result of that query is provided in the mappings
element. |
Examples
Example 22.393. mysqlnd_memcache_get_config
example
<?php
$mysqli = new mysqli("host", "user", "passwd", "database");
$memc = new Memcached();
$memc->addServer("host", 11211);
mysqlnd_memcache_set($mysqli, $memc);
var_dump(mysqlnd_memcache_get_config($mysqli));
?>
The above example will output:
array(4) {
["memcached"]=>
object(Memcached)#2 (0) {
}
["pattern"]=>
string(125) "/^\s*SELECT\s*(.+?)\s*FROM\s*`?([a-z0-9_]+)`?\s*WHERE\s*`?([a-z0-9_]+)`?\s*=\s*(?(?=["'])["']([^"']*)["']|([0-9e\.]*))\s*$/is"
["mappings"]=>
array(1) {
["mymem_test"]=>
array(6) {
["prefix"]=>
string(13) "@@mymem_test."
["schema_name"]=>
string(4) "test"
["table_name"]=>
string(10) "mymem_test"
["id_field_name"]=>
string(2) "id"
["separator"]=>
string(1) "|"
["fields"]=>
array(3) {
[0]=>
string(2) "f1"
[1]=>
string(2) "f2"
[2]=>
string(2) "f3"
}
}
}
["mapping_query"]=>
string(209) " SELECT c.name,
CONCAT('@@', c.name, (SELECT value FROM innodb_memcache.config_options WHERE name = 'table_map_delimiter')) AS key_prefix,
c.db_schema,
c.db_table,
c.key_columns,
c.value_columns,
(SELECT value FROM innodb_memcache.config_options WHERE name = 'separator') AS sep
FROM innodb_memcache.containers c"
}
See Also
mysqlnd_memcache_set
|
Copyright 1997-2012 the PHP Documentation Group.
mysqlnd_memcache_set
Associate a MySQL connection with a Memcache connection
Description
bool mysqlnd_memcache_set(mixed mysql_connection,
Memcached memcache_connection,
string pattern,
callback callback);
Associate mysql_connection with
memcache_connection using
pattern as a PCRE regular expression, and
callback as a notification callback or to
unset the association of
mysql_connection.
While associating a MySQL connection with a Memcache connection,
this function will query the MySQL Server for its configuration.
It will automatically detect whether the server is configured to
use the InnoDB Memcache Daemon Plugin or MySQL Cluster NDB
Memcache support. It will also query the server to automatically
identify exported tables and other configuration options. The
results of this automatic configuration can be retrieved using
mysqlnd_memcache_get_config.
Parameters
mysql_connection
A handle to a MySQL Server using one of the MySQL API extensions for PHP, which are PDO_MYSQL, mysqli or ext/mysql.
memcache_connection
A
Memcached
instance with a connection to the MySQL Memcache Daemon
plugin. If this parameter is omitted, then
mysql_connection will be
unassociated from any memcache connection. And if a
previous association exists, then it will be replaced.
pattern
A regular expression in
Perl Compatible
Regular Expression syntax used to identify
potential Memcache-queries. The query should have three
sub patterns. The first subpattern contains the requested
field list, the second the name of the ID column from the
query and the third the requested value. If this parameter
is omitted or os set to
NULL
, then a default pattern will be used.
callback
A callback which will be used whenever a query is being sent to MySQL. The callback will receive a single boolean parameter telling if a query was sent via Memcache.
Return Values
TRUE
if the association or disassociation is successful, otherwise
FALSE
if there is an error.
Examples
Example 22.394. mysqlnd_memcache_set
example with
var_dump
as a simple debugging callback.
<?php
$mysqli = new mysqli("host", "user", "passwd", "database");
$memc = new Memcached();
$memc->addServer("host", 11211);
mysqlnd_memcache_set($mysqli, $memc, NULL, 'var_dump');
/* This query will be intercepted and executed via Memcache protocol */
echo "Sending query for id via Memcache: ";
$mysqli->query("SELECT f1, f2, f3 FROM test WHERE id = 1");
/* f1 is not configured as valid key field, this won't be sent via Memcache */
echo "Sending query for f1 via Memcache: ";
$mysqli->query("SELECT id FROM test WHERE f1 = 1");
mysqlnd_memcache_set($mysqli);
/* Now the regular MySQL protocol will be used */
echo "var_dump won't be invoked: ";
$mysqli->query("SELECT f1, f2, f3 WHERE id = 1");
?>
The above example will output:
Sending query for id via Memcache: bool(true) Sending query for f1 via Memcache: bool(false) var_dump won't be invoked:
See Also
mysqlnd_memcache_get_config
|

User Comments
Add your own comment.