From a62c5f2622a8439102b89b46a4cb7adc1dbb37a0 Mon Sep 17 00:00:00 2001 From: Anthony Bedford Date: Fri, 9 Jul 2010 14:11:58 +0000 Subject: [PATCH] Initial version of MySQL Native Driver (mysqlnd) Query Cache documentation. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@301130 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/mysqlnd_qc/book.xml | 257 +++++++ reference/mysqlnd_qc/configure.xml | 41 ++ reference/mysqlnd_qc/constants.xml | 124 ++++ reference/mysqlnd_qc/entities.functions.xml | 7 + .../functions/mysqlnd-qc-change-handler.xml | 136 ++++ .../functions/mysqlnd-qc-clear-cache.xml | 77 ++ .../functions/mysqlnd-qc-get-cache-info.xml | 151 ++++ .../functions/mysqlnd-qc-get-core-stats.xml | 508 ++++++++++++++ .../functions/mysqlnd-qc-get-handler.xml | 132 ++++ .../mysqlnd-qc-get-query-trace-log.xml | 363 ++++++++++ .../mysqlnd-qc-set-user-handlers.xml | 189 +++++ reference/mysqlnd_qc/ini.xml | 404 +++++++++++ reference/mysqlnd_qc/reference.xml | 30 + reference/mysqlnd_qc/setup.xml | 48 ++ reference/mysqlnd_qc/usage.xml | 659 ++++++++++++++++++ 15 files changed, 3126 insertions(+) create mode 100644 reference/mysqlnd_qc/book.xml create mode 100644 reference/mysqlnd_qc/configure.xml create mode 100644 reference/mysqlnd_qc/constants.xml create mode 100644 reference/mysqlnd_qc/entities.functions.xml create mode 100644 reference/mysqlnd_qc/functions/mysqlnd-qc-change-handler.xml create mode 100644 reference/mysqlnd_qc/functions/mysqlnd-qc-clear-cache.xml create mode 100644 reference/mysqlnd_qc/functions/mysqlnd-qc-get-cache-info.xml create mode 100644 reference/mysqlnd_qc/functions/mysqlnd-qc-get-core-stats.xml create mode 100644 reference/mysqlnd_qc/functions/mysqlnd-qc-get-handler.xml create mode 100644 reference/mysqlnd_qc/functions/mysqlnd-qc-get-query-trace-log.xml create mode 100644 reference/mysqlnd_qc/functions/mysqlnd-qc-set-user-handlers.xml create mode 100644 reference/mysqlnd_qc/ini.xml create mode 100644 reference/mysqlnd_qc/reference.xml create mode 100644 reference/mysqlnd_qc/setup.xml create mode 100644 reference/mysqlnd_qc/usage.xml diff --git a/reference/mysqlnd_qc/book.xml b/reference/mysqlnd_qc/book.xml new file mode 100644 index 0000000000..87061bfc7c --- /dev/null +++ b/reference/mysqlnd_qc/book.xml @@ -0,0 +1,257 @@ + + + + + + Mysqlnd query result cache plugin + mysqlnd_qc + + + &reftitle.intro; + + The mysqlnd query result cache plugin adds easy to use client-side query + caching to all PHP MySQL extensions using + 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 query cache + plugin, can extend the functionality of + mysqlnd. + + + The MySQL native driver for PHP is a C library which ships together with + PHP as of PHP 5.3.0. It serves as a drop-in replacement for the + MySQL Client Library (AKA libmysql/libmysqlclient). Using mysqlnd has + several advantages: no extra downloads because it comes with PHP, + PHP license, lower memory consumption in certain cases, + new functionality such as asynchronous queries. + + + Mysqlnd plugins such as the query cache plugin operate transparent + from a user perspective. The cache plugin supports all PHP applications + and all PHP MySQL extensions ( + mysqli, + mysql, + PDO_MYSQL). + It does not change existing APIs. + + + No significant application changes are required to cache a query. + The cache has two operation modes. It will either cache all + queries (not recommended) or only those queries marked with a + certain SQL hint (recommended). + + +
+ Key Features + + + + + Transparent and therefore easy to use + + + + + + supports all PHP MySQL extensions + + + + + no API changes + + + + + very little application changes required + + + + + + + + + Flexible invalidation strategy + + + + + + Time-to-Live (TTL) + + + + + user-defined + + + + + + + + + Storage with different scope and life-span + + + + + + Default (Hash) + + + + + APC + + + + + MEMCACHE + + + + + sqlite + + + + + user-defined + + + + + + + +
+ +
+ Limitations + + The query cache plugin prototype will not cache unbuffered + queries or results from prepared statements. This limitation + is likely to be lifted soon. + + + The following popular user API calls use buffered queries which + can be cached: + + + + + + mysqli + + + + mysqli_query + + + + + mysqli_real_query + + mysqli_store_result + + + + + + + + PDO_MYSQL + + + + PDO::query if + PDO::ATTR_EMULATE_PREPARES = 1 (default setting) + + + + + + + + mysql + + + + mysql_query + + + + + + + + +
+ +
+ Architecture + + The query cache is implemented as a PHP extension. + It is written in C and operates under the hood of PHP. During the + startup of the PHP interpreter it gets registered as a + mysqlnd plugin to replace selected + mysqlnd C methods. + + + At PHP run time it proxies queries send from + mysqlnd (PHP) to the MySQL server. If a query string starts with the SQL hint + ( + /*qc=on*/) to enable caching of it and the query + is not cached (cache miss), the query cache plugin will record the + raw wire protocol data send from MySQL to PHP to answer the query. + The query cache records the wire protocol data in its cache + and replays it, if still valid, on a cache hit. + + + Note that the query cache does not hold decoded result sets consisting + of + zvals (C struct representing a PHP variable). + It stores the raw wire data of the MySQL client server protocol. + In case of a cache hits, + mysqlnd still needs + to decode the cached raw wire data into PHP variables before passing + the result to the user space. + This approach has one major advantage: simplicity. Furthermore this + approach eliminates the need for serializing data for cache storage. + +
+ +
+ + + &reference.mysqlnd-qc.setup; + &reference.mysqlnd-qc.constants; + &reference.mysqlnd-qc.usage; + &reference.mysqlnd-qc.reference; + +
+ + diff --git a/reference/mysqlnd_qc/configure.xml b/reference/mysqlnd_qc/configure.xml new file mode 100644 index 0000000000..0662f49db1 --- /dev/null +++ b/reference/mysqlnd_qc/configure.xml @@ -0,0 +1,41 @@ + + + +
+ &reftitle.install; + + &pecl.moved; + + + + &pecl.info; + &url.pecl.package;mysqlnd_qc + + + + &pecl.windows.download; + + +
+ + + diff --git a/reference/mysqlnd_qc/constants.xml b/reference/mysqlnd_qc/constants.xml new file mode 100644 index 0000000000..c26d5d1135 --- /dev/null +++ b/reference/mysqlnd_qc/constants.xml @@ -0,0 +1,124 @@ + + + + + &reftitle.constants; + &extension.constants; + + SQL hint related + + + + + The query cache is controled by SQL hints. SQL hints are used to enable and + disable caching. SQL hints can be used to set the + TTL of a query. + + + The SQL hints recognized by the query cache can be manually changed at + compile time. This makes it possible to use + mysqlnd_qc in environments in which the default + SQL hints are already taken and interpreted by other systems. Therefore + it is recommended to use the SQL hint string constants instead of + manually adding the default SQL hints to the query string. + + + +]]> + + &examples.outputs; + + + + + + + + + + + + MYSQLND_QC_ENABLE_SWITCH + ( + string) + + + + SQL hint used to enable caching of a query. + + + + + + + MYSQLND_QC_DISABLE_SWITCH + ( + string) + + + + SQL hint used to disable caching of a query if + mysqlnd_qc.cache_by_default = 1. + + + + + + MYSQLND_QC_TTL_SWITCH + ( + string) + + + + SQL hint used to set the TTL of a result set. + + + + + + + + + + + + + diff --git a/reference/mysqlnd_qc/entities.functions.xml b/reference/mysqlnd_qc/entities.functions.xml new file mode 100644 index 0000000000..eebcb06dc3 --- /dev/null +++ b/reference/mysqlnd_qc/entities.functions.xml @@ -0,0 +1,7 @@ +&reference.mysqlnd-qc.functions.mysqlnd-qc-change-handler; +&reference.mysqlnd-qc.functions.mysqlnd-qc-clear-cache; +&reference.mysqlnd-qc.functions.mysqlnd-qc-get-cache-info; +&reference.mysqlnd-qc.functions.mysqlnd-qc-get-core-stats; +&reference.mysqlnd-qc.functions.mysqlnd-qc-get-handler; +&reference.mysqlnd-qc.functions.mysqlnd-qc-get-query-trace-log; +&reference.mysqlnd-qc.functions.mysqlnd-qc-set-user-handlers; diff --git a/reference/mysqlnd_qc/functions/mysqlnd-qc-change-handler.xml b/reference/mysqlnd_qc/functions/mysqlnd-qc-change-handler.xml new file mode 100644 index 0000000000..3673723324 --- /dev/null +++ b/reference/mysqlnd_qc/functions/mysqlnd-qc-change-handler.xml @@ -0,0 +1,136 @@ + + + + + + mysqlnd_qc_change_handler + Change current storage handler + + + + &reftitle.description; + + bool + mysqlnd_qc_change_handler + + mixed + handler + + + + Sets the storage handler used by the query cache. A list of available + storage handler can be obtained from mysqlnd_qc_get_handler. + Which storage are available depends on the compile time + configuration of the query cache plugin. The + default storage handler is always available. + All other storage handler must be enabled explicitly when building the + extension. + + + + + + &reftitle.parameters; + + + + handler + + + + Handler can be of type string representing the name of a + built-in storage handler or an object of type + mysqlnd_qc_handler_default. + The names of the built-in storage handler are + default, + APC, + MEMCACHE, + sqlite. + + + + + + + + &reftitle.returnvalues; + + &return.success; + + + If changing the storage handler fails a catchable fatal error will + be thrown. The query cache cannot operate if the previous storage + handler has been shutdown but no new storage handler has been installed. + + + + + &reftitle.examples; + + + The example shows the output from the built-in default storage handler. + Other storage handler may report different data. + + + +]]> + + &examples.outputs; + + + + + + + + + &reftitle.seealso; + + + + Installation + + + mysqlnd_qc_get_handler + + + + + + + + + diff --git a/reference/mysqlnd_qc/functions/mysqlnd-qc-clear-cache.xml b/reference/mysqlnd_qc/functions/mysqlnd-qc-clear-cache.xml new file mode 100644 index 0000000000..ccde9b5421 --- /dev/null +++ b/reference/mysqlnd_qc/functions/mysqlnd-qc-clear-cache.xml @@ -0,0 +1,77 @@ + + + + + + mysqlnd_qc_clear_cache + Flush all cache contents + + + + &reftitle.description; + + bool + mysqlnd_qc_clear_cache + + + + Flush all cache contents. + + + Flushing the cache is a storage handler responsibility. + All built-in storage handler but the + memcache storage + handler support flushing the cache. The + memcache + storage handler cannot flush its cache contents. + + + User-defined storage handler may or may not support the operation. + + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + &return.success; + + + A return value of + FALSE + indicates that flushing all cache contents has + failed or the operation is not supported by + the active storage handler. Applications must + not expect that calling the function will always + flush the cache. + + + + + + + diff --git a/reference/mysqlnd_qc/functions/mysqlnd-qc-get-cache-info.xml b/reference/mysqlnd_qc/functions/mysqlnd-qc-get-cache-info.xml new file mode 100644 index 0000000000..3230725cb4 --- /dev/null +++ b/reference/mysqlnd_qc/functions/mysqlnd-qc-get-cache-info.xml @@ -0,0 +1,151 @@ + + + + + + mysqlnd_qc_get_cache_info + Returns information on the current handler, the number of cache entries and cache entries, if available + + + + &reftitle.description; + + array + mysqlnd_qc_get_cache_info + + + + + + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + Returns information on the current handler, the number of cache entries and + cache entries, if available. If and what data will be returned for the cache + entries is subject to the active storage handler. + Storage handler are free to return any data. Storage handler are + recommended to return at least the data provided by the default handler, + if technically possible. + + + + + &reftitle.examples; + + + The example shows the output from the built-in default storage handler. + Other storage handler may report different data. + + +query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/SELECT id FROM test"); + +/* Display cache information */ +var_dump(mysqlnd_qc_get_cache_info()); +?> +]]> + + &examples.outputs; + + + int(1) + ["handler"]=> + string(7) "default" + ["handler_version"]=> + string(5) "1.0.0" + ["data"]=> + array(1) { + ["Localhost via UNIX socket 3306 user schema|/*qc=on*/SELECT id FROM test"]=> + array(2) { + ["statistics"]=> + array(11) { + ["rows"]=> + int(6) + ["stored_size"]=> + int(101) + ["cache_hits"]=> + int(0) + ["run_time"]=> + int(471) + ["store_time"]=> + int(27) + ["min_run_time"]=> + int(0) + ["max_run_time"]=> + int(0) + ["min_store_time"]=> + int(0) + ["max_store_time"]=> + int(0) + ["avg_run_time"]=> + int(0) + ["avg_store_time"]=> + int(0) + } + ["metadata"]=> + array(1) { + [0]=> + array(8) { + ["name"]=> + string(2) "id" + ["orig_name"]=> + string(2) "id" + ["table"]=> + string(4) "test" + ["orig_table"]=> + string(4) "test" + ["db"]=> + string(4) "schema" + ["max_length"]=> + int(1) + ["length"]=> + int(11) + ["type"]=> + int(3) + } + } + } + } +} + +]]> + + + + + + + + diff --git a/reference/mysqlnd_qc/functions/mysqlnd-qc-get-core-stats.xml b/reference/mysqlnd_qc/functions/mysqlnd-qc-get-core-stats.xml new file mode 100644 index 0000000000..e3d0e1c4fc --- /dev/null +++ b/reference/mysqlnd_qc/functions/mysqlnd-qc-get-core-stats.xml @@ -0,0 +1,508 @@ + + + + + + mysqlnd_qc_get_core_stats + Statistics collected by the core of the query cache + + + + &reftitle.description; + + array + mysqlnd_qc_get_core_stats + + + + Returns an array of statistics collected by the core of the cache plugin. + The same data fields will be reported for any storage handler because the + data is collected by the core. + + + The + PHP configuration setting + mysqlnd_qc.collect_statistics + controls the collection of statistics. The collection of statistics + is disabled by default for performance reasons. + Disabling the collection of statistics will also disable the collection + of time related statistics. + + + The + PHP configuration setting + mysqlnd_qc.collect_time_statistics controls the + collection of time related statistics. + + + The scope of the core statistics is the + PHP process. + Depending on your deployment model a + PHP process may handle one or multiple requests. + + + Statistics are aggregated for all cache entries. It is not possible + to tell how much queries originating from + mysqli, + PDO_MySQL or + mysql API calls have + contributed to the aggregated data values. + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + Array of core statistics + + + + + + + + + Statistic + Description + Version + + + + + + cache_hit + + + Statement is considered cacheable and cached data has been reused. + Statement is considered cacheable and a cache miss happened but + the statement got cached by someone else while we process it and thus + we can fetch the result from the refreshed cache. + + Since 1.0.0. + + + + cache_miss + + + Statement is considered cacheable... + + + + ... and has been added to the cache + + + + + ... but the + PHP + configuration directive setting of + mysqlnd_qc.cache_no_table = 1 has prevented + caching. + + + + + ... but an unbuffered result set is requested. + + + + + ... but a buffered result set was empty. + + + + + Since 1.0.0. + + + + cache_put + + + Statement is considered cacheable and has been added to the cache. + Take care when calculating derived statistics. Storage handler + with a storage life time beyond process scope may report + cache_put = 0 together with + cache_hit > 0, if another process has filled + the cache. You may want to use + num_entries from + mysqlnd_qc_get_cache_info if the handler + supports it ( + default, + APC). + + Since 1.0.0. + + + + query_should_cache + + + Statement is considered cacheable based on query string analysis. + The statement may or may not be added to the cache. See also + cache_put. + + Since 1.0.0. + + + + query_should_not_cache + + + Statement is considered not cacheable based on query string analysis. + + Since 1.0.0. + + + + query_not_cached + + + Statement is considered not cacheable or it is + considered cachable but the storage handler has not returned a + hash key for it. + + Since 1.0.0. + + + + query_could_cache + + + Statement is considered cacheable... + + + + ... and statement has been run without errors + + + + + ... and meta data shows at least one column in the result set + + + + The statement may or may not be in the cache already. + It may or may not be added to the cache later on. + + Since 1.0.0. + + + + query_found_in_cache + + + Statement is considered cacheable and we have found it in the cache + but we have not replayed the cached data yet and we have not send + the result set to the client yet. This is not considered + a cache hit because the client might not fetch the result or + the cached data may be faulty. + + Since 1.0.0. + + + + query_uncached_other + + + Statement is considered cacheable and it may or may not be in + the cache already but either replaying cached data has failed, + no result set is available or some other error has happened. + + + + + query_uncached_no_table + + + Statement has not been cached because the result set has at least + one column which has no table name in its meta data. An example of + such a query is + SELECT SLEEP(1). To cache those + statements you have to change default value of the PHP configuration directive + mysqlnd_qc.cache_no_table and set + mysqlnd_qc.cache_no_table = 1. Often is is not + desired to cache such statements. + + Since 1.0.0. + + + + query_uncached_use_result + + + Statement would have been cached if a buffered result set + had been used. The situation is also consiered as a cache miss and + cache_miss will be incremented as well. + + Since 1.0.0. + + + + query_aggr_run_time_cache_hit + + + Aggregated run time (ms) of all cached queries. + Cached queries are those which have incremented + cache_hit. + + Since 1.0.0. + + + + query_aggr_run_time_cache_put + + + Aggregated run time (ms) of all uncached queries that + have been put into the cache. See also + cache_put. + + Since 1.0.0. + + + + query_aggr_run_time_total + + + Aggregated run time (ms) of all uncached and cached queries + that have been inspected and executed by the query cache. + + Since 1.0.0. + + + + query_aggr_store_time_cache_hit + + + Aggregated store time (ms) of all cached queries. + Cached queries are those which have incremented + cache_hit. + + Since 1.0.0. + + + + query_aggr_store_time_cache_put + + + Aggregated store time ( + ms) of all uncached queries that + have been put into the cache. See also + cache_put. + + Since 1.0.0. + + + + query_aggr_store_time_total + + + Aggregated store time (ms) of all uncached and cached queries + that have been inspected and executed by the query cache. + + Since 1.0.0. + + + + receive_bytes_recorded + + + Recorded incoming network traffic ( + bytes) send from MySQL to PHP. + The traffic may or may not have been added to the cache. The + traffic is the total for all queries regardless if cached or not. + + Since 1.0.0. + + + + receive_bytes_replayed + + + Network traffic replayed during cache. This is the total amount of + incoming traffic saved because of the usage of the query cache plugin. + + Since 1.0.0. + + + + send_bytes_recorded + + + Recorded outgoing network traffic ( + bytes) send from MySQL to PHP. + The traffic may or may not have been added to the cache. The + traffic is the total for all queries regardless if cached or not. + + Since 1.0.0. + + + + send_bytes_replayed + + + Network traffic replayed during cache. This is the total amount of + outgoing traffic saved because of the usage of the query cache plugin. + + Since 1.0.0. + + + + slam_stale_refresh + + + Number of cache misses which triggered serving stale data until + the client causing the cache miss has refreshed the cache entry. + + Since 1.0.0. + + + + slam_stale_hit + + + Number of cache hits while a stale cache entry gets refreshed. + + Since 1.0.0. + + + + + + + + + &reftitle.examples; + + +query("/*qc=on*/SELECT id FROM test"); +/* Cache hit */ +$mysqli->query("/*qc=on*/SELECT id FROM test"); + +/* Display core statstics */ +var_dump(mysqlnd_qc_get_core_stats()); +?> +]]> + + &examples.outputs; + + + string(1) "1" + ["cache_miss"]=> + string(1) "1" + ["cache_put"]=> + string(1) "1" + ["query_should_cache"]=> + string(1) "2" + ["query_should_not_cache"]=> + string(1) "0" + ["query_not_cached"]=> + string(1) "0" + ["query_could_cache"]=> + string(1) "2" + ["query_found_in_cache"]=> + string(1) "1" + ["query_uncached_other"]=> + string(1) "0" + ["query_uncached_no_table"]=> + string(1) "0" + ["query_uncached_no_result"]=> + string(1) "0" + ["query_uncached_use_result"]=> + string(1) "0" + ["query_aggr_run_time_cache_hit"]=> + string(1) "4" + ["query_aggr_run_time_cache_put"]=> + string(3) "395" + ["query_aggr_run_time_total"]=> + string(3) "399" + ["query_aggr_store_time_cache_hit"]=> + string(1) "2" + ["query_aggr_store_time_cache_put"]=> + string(1) "8" + ["query_aggr_store_time_total"]=> + string(2) "10" + ["receive_bytes_recorded"]=> + string(2) "65" + ["receive_bytes_replayed"]=> + string(2) "65" + ["send_bytes_recorded"]=> + string(2) "29" + ["send_bytes_replayed"]=> + string(2) "29" + ["slam_stale_refresh"]=> + string(1) "0" + ["slam_stale_hit"]=> + string(1) "0" + ["request_counter"]=> + int(1) + ["process_hash"]=> + int(3547549858) +} + +]]> + + + + + + + &reftitle.seealso; + + + + Runtime configuration + + + mysqlnd_qc.collect_statistics + + + mysqlnd_qc.time_statistics + + + + + + + + diff --git a/reference/mysqlnd_qc/functions/mysqlnd-qc-get-handler.xml b/reference/mysqlnd_qc/functions/mysqlnd-qc-get-handler.xml new file mode 100644 index 0000000000..ca6179f864 --- /dev/null +++ b/reference/mysqlnd_qc/functions/mysqlnd-qc-get-handler.xml @@ -0,0 +1,132 @@ + + + + + + mysqlnd_qc_get_handler + Returns a list of available storage handler + + + + &reftitle.description; + + array + mysqlnd_qc_get_handler + + + + Which storage are available depends on the compile time + configuration of the query cache plugin. The + default storage handler is always available. + All other storage handler must be enabled explicitly when building the + extension. + + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + Returns an array of available built-in storage handler. + For each storage handler the version number and version string + is given. + + + + + &reftitle.examples; + + + +]]> + + &examples.outputs; + + + array(2) { + ["version"]=> + string(5) "1.0.0" + ["version_number"]=> + int(100000) + } + ["user"]=> + array(2) { + ["version"]=> + string(5) "1.0.0" + ["version_number"]=> + int(100000) + } + ["APC"]=> + array(2) { + ["version"]=> + string(5) "1.0.0" + ["version_number"]=> + int(100000) + } + ["MEMCACHE"]=> + array(2) { + ["version"]=> + string(5) "1.0.0" + ["version_number"]=> + int(100000) + } + ["sqlite"]=> + array(2) { + ["version"]=> + string(5) "1.0.0" + ["version_number"]=> + int(100000) + } +} +]]> + + + + + + + &reftitle.seealso; + + + + Installation + + + mysqlnd_qc_change_handler + + + + + + + + diff --git a/reference/mysqlnd_qc/functions/mysqlnd-qc-get-query-trace-log.xml b/reference/mysqlnd_qc/functions/mysqlnd-qc-get-query-trace-log.xml new file mode 100644 index 0000000000..c81bb59211 --- /dev/null +++ b/reference/mysqlnd_qc/functions/mysqlnd-qc-get-query-trace-log.xml @@ -0,0 +1,363 @@ + + + + + + mysqlnd_qc_get_query_trace_log + Returns a backtrace for each query inspected by the query cache + + + + &reftitle.description; + + array + mysqlnd_qc_get_query_trace_log + + + + Returns a backtrace for each query inspected by the query cache. + The collection of the backtrace is disabled by default. To collect + the backtrace you have to set the PHP configuration directive + mysqlnd_qc.collect_query_trace to + 1 + + + The maximum depth of the backtrace is limited to the depth set + with the PHP configuration directive + mysqlnd_qc.query_trace_bt_depth. + + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + An array of query backtrace. Every list entry contains + the query string, a backtrace and further detail information. + + + + + + + + + Key + Description + + + + + + query + + + Query string. + + + + + origin + + + Code backtrace. + + + + + run_time + + + Query run time in milliseconds. The collection of + of all times and the necessary + gettimeofday + system calls can be disabled by setting the PHP configuration + directive + mysqlnd_qc.time_statistics to + 0 + + + + + store_time + + + Query result set store time in milliseconds. The collection of + of all times and the necessary + gettimeofday + system calls can be disabled by setting the PHP configuration + directive + mysqlnd_qc.time_statistics to + 0 + + + + + eligible_for_caching + + + TRUE if query is cacheble otherwise + FALSE. + + + + + no_table + + + TRUE if the query has generated a result + set and at least one column from the result set has no table + name set in its metadata. This is usually the case with + queries which one probably do not want to cache such as + SELECT SLEEP(1). By default any such query + will not be added to the cache. See also PHP configuration directive + mysqlnd_qc.cache_no_table. + + + + + was_added + + + TRUE if the query result has been put into + the cache, otherwise + FALSE. + + + + + was_already_in_cache + + + TRUE if the query result would have been + added to the cache if it was not already in the cache (cache hit). + Otherwise + FALSE. + + + + + + + + + + + &reftitle.examples; + + +query("DROP TABLE IF EXISTS test"); +$mysqli->query("CREATE TABLE test(id INT)"); +$mysqli->query("INSERT INTO test(id) VALUES (1), (2)"); + +$res = $mysqli->query("SELECT id FROM test WHERE id = 1"); +var_dump($res->fetch_assoc()); +$res->free(); + +$res = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 2"); +var_dump($res->fetch_assoc()); +$res->free(); + +$res = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 2"); +var_dump($res->fetch_assoc()); +$res->free(); +?> +]]> + + &examples.outputs; + + + string(1) "1" +} +array(1) { + ["id"]=> + string(1) "2" +} +array(1) { + ["id"]=> + string(1) "2" +} +array(6) { + [0]=> + array(8) { + ["query"]=> + string(25) "DROP TABLE IF EXISTS test" + ["origin"]=> + string(85) "#0 /home/nixnutz/php/phpdoc/foo.php(7): mysqli->query('DROP TABLE IF E...') +#1 {main}" + ["run_time"]=> + int(0) + ["store_time"]=> + int(0) + ["eligible_for_caching"]=> + bool(false) + ["no_table"]=> + bool(false) + ["was_added"]=> + bool(false) + ["was_already_in_cache"]=> + bool(false) + } + [1]=> + array(8) { + ["query"]=> + string(25) "CREATE TABLE test(id INT)" + ["origin"]=> + string(85) "#0 /home/nixnutz/php/phpdoc/foo.php(8): mysqli->query('CREATE TABLE te...') +#1 {main}" + ["run_time"]=> + int(0) + ["store_time"]=> + int(0) + ["eligible_for_caching"]=> + bool(false) + ["no_table"]=> + bool(false) + ["was_added"]=> + bool(false) + ["was_already_in_cache"]=> + bool(false) + } + [2]=> + array(8) { + ["query"]=> + string(36) "INSERT INTO test(id) VALUES (1), (2)" + ["origin"]=> + string(85) "#0 /home/nixnutz/php/phpdoc/foo.php(9): mysqli->query('INSERT INTO tes...') +#1 {main}" + ["run_time"]=> + int(0) + ["store_time"]=> + int(0) + ["eligible_for_caching"]=> + bool(false) + ["no_table"]=> + bool(false) + ["was_added"]=> + bool(false) + ["was_already_in_cache"]=> + bool(false) + } + [3]=> + array(8) { + ["query"]=> + string(32) "SELECT id FROM test WHERE id = 1" + ["origin"]=> + string(86) "#0 /home/nixnutz/php/phpdoc/foo.php(11): mysqli->query('SELECT id FROM ...') +#1 {main}" + ["run_time"]=> + int(0) + ["store_time"]=> + int(15) + ["eligible_for_caching"]=> + bool(false) + ["no_table"]=> + bool(false) + ["was_added"]=> + bool(false) + ["was_already_in_cache"]=> + bool(false) + } + [4]=> + array(8) { + ["query"]=> + string(41) "/*qc=on*/SELECT id FROM test WHERE id = 2" + ["origin"]=> + string(86) "#0 /home/nixnutz/php/phpdoc/foo.php(15): mysqli->query('/*qc=on*/SELECT...') +#1 {main}" + ["run_time"]=> + int(340) + ["store_time"]=> + int(3) + ["eligible_for_caching"]=> + bool(true) + ["no_table"]=> + bool(false) + ["was_added"]=> + bool(true) + ["was_already_in_cache"]=> + bool(false) + } + [5]=> + array(8) { + ["query"]=> + string(41) "/*qc=on*/SELECT id FROM test WHERE id = 2" + ["origin"]=> + string(86) "#0 /home/nixnutz/php/phpdoc/foo.php(19): mysqli->query('/*qc=on*/SELECT...') +#1 {main}" + ["run_time"]=> + int(4) + ["store_time"]=> + int(2) + ["eligible_for_caching"]=> + bool(true) + ["no_table"]=> + bool(false) + ["was_added"]=> + bool(false) + ["was_already_in_cache"]=> + bool(true) + } +} +]]> + + + + + + + &reftitle.seealso; + + + + Runtime configuration + + + mysqlnd_qc.collect_query_trace + + + mysqlnd_qc.query_trace_bt_depth + + + mysqlnd_qc.time_statistics + + + mysqlnd_qc.cache_no_table + + + + + + + + diff --git a/reference/mysqlnd_qc/functions/mysqlnd-qc-set-user-handlers.xml b/reference/mysqlnd_qc/functions/mysqlnd-qc-set-user-handlers.xml new file mode 100644 index 0000000000..578bb87cb6 --- /dev/null +++ b/reference/mysqlnd_qc/functions/mysqlnd-qc-set-user-handlers.xml @@ -0,0 +1,189 @@ + + + + + + mysqlnd_qc_set_user_handlers + Sets the callback functions for a user-defined procedural storage handler + + + + &reftitle.description; + + bool + mysqlnd_qc_set_user_handlers + + string + get_hash + + + string + find_query_in_cache + + + string + return_to_cache + + + string + add_query_to_cache_if_not_exists + + + string + query_is_select + + + string + update_query_run_time_stats + + + string + get_stats + + + string + clear_cache + + + + Sets the callback functions for a user-defined procedural storage handler. + + + + + + + + &reftitle.parameters; + + + + get_hash + + + + Name of the user function implementing the storage handler + get_hash functionality. + + + + + + find_query_in_cache + + + + Name of the user function implementing the storage handler + find_in_cache functionality. + + + + + + return_to_cache + + + + Name of the user function implementing the storage handler + return_to_cache functionality. + + + + + + add_query_to_cache_if_not_exists + + + + Name of the user function implementing the storage handler + add_query_to_cache_if_not_exists functionality. + + + + + + query_is_select + + + + Name of the user function implementing the storage handler + query_is_select functionality. + + + + + + update_query_run_time_stats + + + + Name of the user function implementing the storage handler + update_query_run_time_stats functionality. + + + + + + get_stats + + + + Name of the user function implementing the storage handler + get_stats functionality. + + + + + + clear_cache + + + + Name of the user function implementing the storage handler + clear_cache functionality. + + + + + + + + &reftitle.returnvalues; + + Returns TRUE on success or FALSE on FAILURE. + + + + + &reftitle.seealso; + + + + Procedural user-defined storage handler example + + + + + + + + diff --git a/reference/mysqlnd_qc/ini.xml b/reference/mysqlnd_qc/ini.xml new file mode 100644 index 0000000000..530743d229 --- /dev/null +++ b/reference/mysqlnd_qc/ini.xml @@ -0,0 +1,404 @@ + + + +
+ &reftitle.runtime; + &extension.runtime; + + + mysqlnd_qc &ConfigureOptions; + + + + &Name; + &Default; + &Changeable; + &Changelog; + + + + + mysqlnd_qc.enable_qc + 1 + PHP_INI_SYSTEM + + + + + mysqlnd_qc.ttl + 30 + PHP_INI_ALL + + + + + mysqlnd_qc.cache_by_default + 0 + PHP_INI_ALL + + + + + mysqlnd_qc.cache_no_table + 0 + PHP_INI_ALL + + + + + mysqlnd_qc.use_request_time + 0 + PHP_INI_ALL + + + + + mysqlnd_qc.time_statistics + 1 + PHP_INI_ALL + + + + + mysqlnd_qc.collect_statistics + 0 + PHP_INI_ALL + + + + + mysqlnd_qc.collect_query_trace + 0 + PHP_INI_SYSTEM + + + + + mysqlnd_qc.query_trace_bt_depth + 3 + PHP_INI_SYSTEM + + + + + mysqlnd_qc.slam_defense + 0 + PHP_INI_SYSTEM + + + + + mysqlnd_qc.slam_defense_ttl + 30 + PHP_INI_SYSTEM + + + + + mysqlnd_qc.collect_normalized_query_trace + 0 + PHP_INI_SYSTEM + + + + + mysqlnd_qc.std_data_copy + 0 + PHP_INI_SYSTEM + + + + + mysqlnd_qc.apc_prefix + qc_ + PHP_INI_ALL + + + + + mysqlnd_qc.memc_server + 127.0.0.1 + PHP_INI_ALL + + + + + mysqlnd_qc.memc_port + 11211 + PHP_INI_ALL + + + + + mysqlnd_qc.sqlite_data_file + :memory: + PHP_INI_ALL + + + + + +
+
+ + &ini.descriptions.title; + + + + + + mysqlnd_qc.enable_qc + integer + + + + Enables or disables the plugin. If disabled the extension will not plug + into + mysqlnd to proxy internal + mysqlnd C API calls. + + + + + + mysqlnd_qc.ttl + integer + + + + Default Time-to-Live (TTL) for cache entries in seconds. + + + + + + mysqlnd_qc.cache_by_default + integer + + + + Cache all queries regardless if they begin with the SQL hint that + enables caching of a query or not. Storage handler cannot overrule + the setting. It is evaluated by the core of the plugin. + + + + + + mysqlnd_qc.cache_no_table + integer + + + + Cache queries with no table name in any of columns meta data + of their result set, e.g. + SELECT SLEEP(1)? + + + + + + mysqlnd_qc.use_request_time + integer + + + + Use PHP global request time to avoid + gettimeofday() system calls? + If using + + APC + storage handler + it should be set to the value of + + apc.use_request_time + , if not + warnings will be generated. + + + + + + mysqlnd_qc.time_statistics + integer + + + + Collect run time and store time statistics using + gettimeofday() system call? Data will be + collected only if you also set + mysqlnd_qc.collect_statistics = 1, + + + + + + mysqlnd_qc.collect_statistics + integer + + + + Collect statistics for + mysqlnd_qc_get_core_stats()? + Does not influence storage handler statistics! Handler statistics + can be an integral part of the handler internal storage format. + Thereofore, collection of some handler statistics cannot be disabled. + + + + + + mysqlnd_qc.collect_query_trace + integer + + + + Collect query back traces? + + + + + + mysqlnd_qc.query_trace_bt_depth + integer + + + + Maximum depth/level of a query code backtrace. + + + + + + mysqlnd_qc.slam_defense + integer + + + + Activates handler based slam defense if available. + Supported by + Default and + + APC + storage handler + + + + + + mysqlnd_qc.slam_defense_ttl + integer + + + + TTL for stale cache entries which are + served while another client updates the entries. Supported by + + APC + + storage handler. + + + + + + mysqlnd_qc.collect_normalized_query_trace + integer + + + + Collect aggregated normalized query traces? The setting + has no effect by default. You compile the extension + using the define + NORM_QUERY_TRACE_LOG to make use of the setting. + + + + + + mysqlnd_qc.std_data_copy + integer + + + + Default storage handler: copy cached wire data? + EXPERIMENTAL – use default setting! + + + + + + mysqlnd_qc.apc_prefix + string + + + + The + + APC + storage handler stores data in the + APC user cache. The setting sets a prefix to be + used for cache entries. + + + + + + mysqlnd_qc.memc_server + string + + + + MEMCACHE storage handler: memcache server host. + + + + + + mysqlnd_qc.memc_port + integer + + + + MEMCACHE storage handler: memcached server port. + + + + + + mysqlnd_qc.sqlite_data_file + string + + + + sqlite storage handler: data file. Any setting + but + :memory: may be of little practical value. + + + + + + +
+ + diff --git a/reference/mysqlnd_qc/reference.xml b/reference/mysqlnd_qc/reference.xml new file mode 100644 index 0000000000..559f8e9554 --- /dev/null +++ b/reference/mysqlnd_qc/reference.xml @@ -0,0 +1,30 @@ + + + + + mysqlnd_qc &Functions; + + &reference.mysqlnd-qc.entities.functions; + + + + diff --git a/reference/mysqlnd_qc/setup.xml b/reference/mysqlnd_qc/setup.xml new file mode 100644 index 0000000000..cf85569efe --- /dev/null +++ b/reference/mysqlnd_qc/setup.xml @@ -0,0 +1,48 @@ + + + + + &reftitle.setup; + +
+ &reftitle.required; + +PHP 5.3.3 or newer. + + + For using APC storage handler: APC 3.1.3p1-beta or newer. + + + For using MEMCACHE storage handler: libmemcache 0.38 or newer. + + + For using sqlite storage handler: sqlite3 bundled with PHP. + + +
+ + &reference.mysqlnd-qc.configure; + &reference.mysqlnd-qc.ini; + +
+ + diff --git a/reference/mysqlnd_qc/usage.xml b/reference/mysqlnd_qc/usage.xml new file mode 100644 index 0000000000..0213194b9f --- /dev/null +++ b/reference/mysqlnd_qc/usage.xml @@ -0,0 +1,659 @@ + + + + + &reftitle.examples; + +
+ Basic usage + + The Query Cache plugin supports caching of queries issued by the following user API calls: + + + + + + + mysqli + + + + mysqli_query + + + + + mysqli_real_query + + mysqli_store_result + + + + + + + + PDO_MYSQL + + + + PDO::query if + PDO::ATTR_EMULATE_PREPARES = 1 (default setting) + + + + + + + + mysql + + + + mysql_query + + + + + + + + + + + A query which shall be cached must begin with the SQL hint + /*qc=on*/. It is recommended to use the PHP constant + + MYSQLND_QC_ENABLE_SWITCH + instead of using the string value. + + + + + + uncached: + SELECT id FROM test + + + + + cached: + /*qc=on*/SELECT id FROM test + + + + + + Example using the most advanced PHP MySQL API, which is + + mysqli + : + + + + +query("DROP TABLE IF EXISTS test"); +$mysqli->query("CREATE TABLE test(id INT)"); +$mysqli->query("INSERT INTO test(id) VALUES (1), (2)"); + +/* Will be cached because of the SQL hint: cache put and cache_miss */ +$res = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 1"); +var_dump($res->fetch_assoc()); +$res->free(); + +/* Will NOT be cached and will NOT hit the cache: no SQL hint */ +$res = $mysqli->query("SELECT id FROM test WHERE id = 2"); +var_dump($res->fetch_assoc()); +$res->free(); + +/* Display cache statistics */ +$stats = mysqlnd_qc_get_core_stats(); +printf("Cache hit\t: %d\n", $stats['cache_hit']); +printf("Cache miss\t: %d\n", $stats['cache_miss']); +printf("Cache put\t: %d\n", $stats['cache_put']); + +?> +]]> + + &examples.outputs; + + + string(1) "1" +} +array(1) { + ["id"]=> + string(1) "2" +} +Cache hit : 0 +Cache miss : 1 +Cache put : 1 +]]> + + + + + + The default invalidation strategy of the cache is Time-to-Live ( + TTL). Cache entries are valid for a certain duration. + The default duration is set by the PHP configuration directive + + mysqlnd_qc.tll + + +
+ +
+ Setting the TTL + + The default invalidation strategy of the query cache plugin is Time-to-Live ( + TTL). The built-in storage handler will use the default + TTL defined by the PHP configuration value + + mysqlnd_qc.ttl + unless the query string contains + a hint for setting a different + TTL. The + TTL is specified in seconds. + + + Any + TTL based cache can serve stale data. Cache entries + are not automatically invalidated, if underlying data changes. + + + User-defined cache storage handler can implement any invalidation strategy + to work around this limitation. + + + + +query("DROP TABLE IF EXISTS test"); +$mysqli->query("CREATE TABLE test(id INT)"); +$mysqli->query("INSERT INTO test(id) VALUES (1), (2)"); + +printf("Default TTL\t: %d seconds\n", ini_get("mysqlnd_qc.ttl")); + +/* Will be cached because of the SQL hint */ +$res = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 1"); +var_dump($res->fetch_assoc()); +$res->free(); + +$mysqli->query("DELETE FROM test WHERE id = 1"); + +/* Cache hit - no automatic invalidation! */ +$res = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 1"); +var_dump($res->fetch_assoc()); +$res->free(); + +sleep(ini_get("mysqlnd_qc.ttl")); + +/* Cache miss - cache entry has expired */ +$res = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 1"); +var_dump($res->fetch_assoc()); +$res->free(); + +?> +]]> + + &examples.outputs; + + + string(1) "1" +} +array(1) { + ["id"]=> + string(1) "1" +} +NULL +]]> + + + + + + The default + TTL can be overruled using the SQL hint + /*qc_tt=seconds*/. The SQL hint must be appear immediately + after the SQL hint which enables caching. It is recommended to use + the PHP constant + + MYSQLND_QC_TTL_SWITCH + instead of + using the string value. + + + + +query("DROP TABLE IF EXISTS test"); +$mysqli->query("CREATE TABLE test(id INT)"); +$mysqli->query("INSERT INTO test(id) VALUES (1), (2)"); + +printf("Default TTL\t: %d seconds\n", ini_get("mysqlnd_qc.ttl")); + +/* Will be cached for 2 seconds */ +$sql = sprintf("/*%s*//*%s%d*/SELECT id FROM test WHERE id = 1", + MYSQLND_QC_ENABLE_SWITCH, + MYSQLND_QC_TTL_SWITCH, + 2); +$res = $mysqli->query($sql); +var_dump($res->fetch_assoc()); +$res->free(); + +$mysqli->query("DELETE FROM test WHERE id = 1"); +sleep(1); + +/* Cache hit - no automatic invalidation and still valid! */ +$res = $mysqli->query($sql); +var_dump($res->fetch_assoc()); +$res->free(); + +sleep(2); + +/* Cache miss - cache entry has expired */ +$res = $mysqli->query($sql); +var_dump($res->fetch_assoc()); +$res->free(); + +printf("Script runtime\t: %d seconds\n", microtime(true) - $start); + +?> +]]> + + &examples.outputs; + + + string(1) "1" +} +array(1) { + ["id"]=> + string(1) "1" +} +NULL +Script runtime : 3 seconds + +]]> + + + + + +
+ +
+ Cache by default + + The query cache plugin will cache all queries regardless if + the query string begins with the SQL hint which enables caching or not, + if the PHP configuration directive + + mysqlnd_qc.cache_by_default + is set to + 1. + The setting + + mysqlnd_qc.cache_by_default + is evaluated + by the core of the query cache plugins. Neither the built-in nor + user-defined storage handler can overrule the setting. + + + The SQL hint + /*qc=off*/ can be used to disable caching + of individual queries if + + mysqlnd_qc.cache_by_default = 1 + + It is recommended to use the PHP constant + + MYSQLND_QC_DISABLE_SWITCH + instead of + using the string value. + + + + +query("DROP TABLE IF EXISTS test"); +$mysqli->query("CREATE TABLE test(id INT)"); +$mysqli->query("INSERT INTO test(id) VALUES (1), (2)"); + + +/* Will be cached although no SQL hint is present because of mysqlnd_qc.cache_by_default = 1*/ +$res = $mysqli->query("SELECT id FROM test WHERE id = 1"); +var_dump($res->fetch_assoc()); +$res->free(); + +$mysqli->query("DELETE FROM test WHERE id = 1"); + +/* Cache hit - no automatic invalidation and still valid! */ +$res = $mysqli->query("SELECT id FROM test WHERE id = 1"); +var_dump($res->fetch_assoc()); +$res->free(); + +/* Cache miss - query must not be cached or served from cache because of the SQL hint */ +$res = $mysqli->query("/*" . MYSQLND_QC_DISABLE_SWITCH . "*/SELECT id FROM test WHERE id = 1"); +var_dump($res->fetch_assoc()); +$res->free(); + +?> +]]> + + &examples.outputs; + + + string(1) "1" +} +array(1) { + ["id"]=> + string(1) "1" +} +NULL +]]> + + + + +
+ + +
+ Procedural user-defined storage handler + + The query cache plugin supports the use of user-defined storage handler. + User-defined storage handler can use arbitrarily complex invalidation + algorithms and support arbitrary storage media. + + + All user-defined storage handlers have to provide a certain interface. + The functions of the user-defined storage handler will be called by the + core of the cache plugin. The necessary interface consists of seven + public functions. Both procedural and object oriented user-defined storage + handler must implement the same set of functions. + + + Please check the example for details. + + + + + $data, + "row_count" => $row_count, + "valid_until" => time() + $ttl, + "hits" => 0, + "run_time" => $run_time, + "store_time" => $store_time, + "cached_run_times" => array(), + "cached_store_times" => array(), + ); + + return TRUE; +} + +function query_is_select($query) { + printf("\t%s('%s'): ", __FUNCTION__, $query); + + $ret = FALSE; + if (stristr($query, "SELECT") !== FALSE) { + /* cache for 5 seconds */ + $ret = 5; + } + + printf("%s\n", (FALSE === $ret) ? "FALSE" : $ret); + return $ret; +} + +function update_query_run_time_stats($key, $run_time, $store_time) { + global $__cache; + printf("\t%s(%d)\n", __FUNCTION__, func_num_args()); + + if (isset($__cache[$key])) { + $__cache[$key]['hits']++; + $__cache[$key]["cached_run_times"][] = $run_time; + $__cache[$key]["cached_store_times"][] = $store_time; + } +} + +function get_stats($key = NULL) { + global $__cache; + printf("\t%s(%d)\n", __FUNCTION__, func_num_args()); + + if ($key && isset($__cache[$key])) { + $stats = $__cache[$key]; + } else { + $stats = array(); + foreach ($__cache as $key => $details) { + $stats[$key] = array( + 'hits' => $details['hits'], + 'bytes' => strlen($details['data']), + 'uncached_run_time' => $details['run_time'], + 'cached_run_time' => (count($details['cached_run_times'])) + ? array_sum($details['cached_run_times']) / count($details['cached_run_times']) + : 0, + ); + } + } + + return $stats; +} + +function clear_cache() { + global $__cache; + printf("\t%s(%d)\n", __FUNCTION__, func_num_args()); + + $__cache = array(); + return TRUE; +} + +/* Install procedural user-defined storage handler */ +if (!mysqlnd_qc_set_user_handlers("get_hash", "find_query_in_cache", + "return_to_cache", "add_query_to_cache_if_not_exists", + "query_is_select", "update_query_run_time_stats", + "get_stats", "clear_cache")) { + printf("Failed to install user-defined storage handler\n"); +} + + +/* Connect, create and populate test table */ +$mysqli = new mysqli("host", "user", "password", "schema", "port", "socket"); +$mysqli->query("DROP TABLE IF EXISTS test"); +$mysqli->query("CREATE TABLE test(id INT)"); +$mysqli->query("INSERT INTO test(id) VALUES (1), (2)"); + +printf("\nCache put/cache miss\n"); + +$res = $mysqli->query("SELECT id FROM test WHERE id = 1"); +var_dump($res->fetch_assoc()); +$res->free(); + +/* Delete record to verify we get our data from the cache */ +$mysqli->query("DELETE FROM test WHERE id = 1"); + +printf("\nCache hit\n"); + +$res = $mysqli->query("SELECT id FROM test WHERE id = 1"); +var_dump($res->fetch_assoc()); +$res->free(); + +printf("\nDisplay cache statistics\n"); +var_dump(mysqlnd_qc_get_cache_info()); + +printf("\nFlushing cache, cache put/cache miss"); +var_dump(mysqlnd_qc_clear_cache()); + +$res = $mysqli->query("SELECT id FROM test WHERE id = 1"); +var_dump($res->fetch_assoc()); +$res->free(); +?> +]]> + + &examples.outputs; + + + string(1) "1" +} + query_is_select('DELETE FROM test WHERE id = 1'): FALSE + +Cache hit + query_is_select('SELECT id FROM test WHERE id = 1'): 5 + get_hash(5) + find_query_in_cache(1) + return_to_cache(1) + update_query_run_time_stats(3) +array(1) { + ["id"]=> + string(1) "1" +} + +Display cache statistics + get_stats(0) +array(4) { + ["num_entries"]=> + int(1) + ["handler"]=> + string(4) "user" + ["handler_version"]=> + string(5) "1.0.0" + ["data"]=> + array(1) { + ["18683c177dc89bb352b29965d112fdaa"]=> + array(4) { + ["hits"]=> + int(1) + ["bytes"]=> + int(71) + ["uncached_run_time"]=> + int(398) + ["cached_run_time"]=> + int(4) + } + } +} + +Flushing cache, cache put/cache miss clear_cache(0) +bool(true) + query_is_select('SELECT id FROM test WHERE id = 1'): 5 + get_hash(5) + find_query_in_cache(1) + add_query_to_cache_if_not_exists(6) +NULL + +]]> + + + + +
+ +
+ +