<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Caching queries</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mysqlnd-qc.quickstart.configuration.html">Setup</a></div> <div class="next" style="text-align: right; float: right;"><a href="mysqlnd-qc.per-query-ttl.html">Setting the TTL</a></div> <div class="up"><a href="mysqlnd-qc.quickstart.html">Quickstart and Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mysqlnd-qc.quickstart.caching" class="section"> <h2 class="title">Caching queries</h2> <p class="para"> There are four ways to trigger caching of a query. <ul class="itemizedlist"> <li class="listitem"> <span class="simpara">Use of SQL hints on a per query basis</span> </li> <li class="listitem"> <span class="simpara"> User supplied callbacks to decide on a per query basis, for example, using <span class="function"><strong>mysqlnd_qc_is_select()</strong></span> </span> </li> <li class="listitem"> <span class="simpara"> <span class="function"><strong>mysqlnd_set_cache_condition()</strong></span> for rule based automatic per query decisions </span> </li> <li class="listitem"> <span class="simpara"> <em><a href="mysqlnd-qc.configuration.html" class="link">mysqlnd_qc.cache_by_default = 1</a></em> to cache all queries blindly </span> </li> </ul> </p> <p class="para"> Use of SQL hints and <em><a href="mysqlnd-qc.configuration.html" class="link">mysqlnd_qc.cache_by_default = 1</a></em> are explained below. Please, refer to the function reference on <span class="function"><strong>mysqlnd_qc_is_select()</strong></span> for a description of using a callback and, <span class="function"><a href="function.mysqlnd-qc-set-cache-condition.html" class="function">mysqlnd_qc_set_cache_condition()</a></span> on how to set rules for automatic caching. </p> <p class="para"> A SQL hint is a SQL standards compliant comment. As a SQL comment it is ignored by the database. A statement is considered eligible for caching if it either begins with the SQL hint enabling caching or it is a <em>SELECT</em> statement. </p> <p class="para"> An individual query which shall be cached must begin with the SQL hint <em>/*qc=on*/</em>. It is recommended to use the PHP constant <em><a href="mysqlnd-qc.constants.html" class="link">MYSQLND_QC_ENABLE_SWITCH</a></em> instead of using the string value. </p> <p class="para"> <ul class="itemizedlist"> <li class="listitem"> <p class="para"> not eligible for caching and not cached: <em>INSERT INTO test(id) VALUES (1)</em> </p> </li> <li class="listitem"> <p class="para"> not eligible for caching and not cached: <em>SHOW ENGINES</em> </p> </li> <li class="listitem"> <p class="para"> eligible for caching but uncached: <em>SELECT id FROM test</em> </p> </li> <li class="listitem"> <p class="para"> eligible for caching and cached: <em>/*qc=on*/SELECT id FROM test</em> </p> </li> </ul> </p> <p class="para"> The examples <em>SELECT</em> statement string is prefixed with the <em><a href="mysqlnd-qc.constants.html" class="link">MYSQLND_QC_ENABLE_SWITCH</a></em> SQL hint to enable caching of the statement. The SQL hint must be given at the very beginning of the statement string to enable caching. </p> <p class="para"> <div class="example" id="example-1846"> <p><strong>Example #1 Using the <em>MYSQLND_QC_ENABLE_SWITCH</em> SQL hint</strong></p> <div class="example-contents"> <div class="inicode"><pre class="inicode">mysqlnd_qc.enable_qc=1</pre> </div> </div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Connect, create and populate test table */<br /></span><span style="color: #0000BB">$mysqli </span><span style="color: #007700">= new </span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"host"</span><span style="color: #007700">, </span><span style="color: #DD0000">"user"</span><span style="color: #007700">, </span><span style="color: #DD0000">"password"</span><span style="color: #007700">, </span><span style="color: #DD0000">"schema"</span><span style="color: #007700">, </span><span style="color: #DD0000">"port"</span><span style="color: #007700">, </span><span style="color: #DD0000">"socket"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP TABLE IF EXISTS test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE TABLE test(id INT)"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO test(id) VALUES (1), (2)"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Will be cached because of the SQL hint */<br /></span><span style="color: #0000BB">$start </span><span style="color: #007700">= </span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"/*" </span><span style="color: #007700">. </span><span style="color: #0000BB">MYSQLND_QC_ENABLE_SWITCH </span><span style="color: #007700">. </span><span style="color: #DD0000">"*/" </span><span style="color: #007700">. </span><span style="color: #DD0000">"SELECT id FROM test WHERE id = 1"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">free</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Total time uncached query: %.6fs\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">) - </span><span style="color: #0000BB">$start</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Cache hit */<br /></span><span style="color: #0000BB">$start </span><span style="color: #007700">= </span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"/*" </span><span style="color: #007700">. </span><span style="color: #0000BB">MYSQLND_QC_ENABLE_SWITCH </span><span style="color: #007700">. </span><span style="color: #DD0000">"*/" </span><span style="color: #007700">. </span><span style="color: #DD0000">"SELECT id FROM test WHERE id = 1"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">free</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Total time cached query: %.6fs\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">) - </span><span style="color: #0000BB">$start</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above examples will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> array(1) { ["id"]=> string(1) "1" } Total time uncached query: 0.000740s array(1) { ["id"]=> string(1) "1" } Total time cached query: 0.000098s </pre></div> </div> </div> </p> <p class="para"> If nothing else is configured, as it is the case in the quickstart example, the plugin will use the built-in <em>default</em> storage handler. The <em>default</em> storage handler uses process memory to hold a cache entry. Depending on the PHP deployment model, a PHP process may serve one or more web requests. Please, consult the web server manual for details. Details make no difference for the examples given in the quickstart. </p> <p class="para"> 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 <em><a href="mysqlnd-qc.configuration.html" class="link">mysqlnd_qc.cache_by_default</a></em> is set to <em>1</em>. The setting <em><a href="mysqlnd-qc.configuration.html" class="link">mysqlnd_qc.cache_by_default</a></em> is evaluated by the core of the query cache plugins. Neither the built-in nor user-defined storage handler can overrule the setting. </p> <p class="para"> The SQL hint <em>/*qc=off*/</em> can be used to disable caching of individual queries if <em><a href="mysqlnd-qc.configuration.html" class="link">mysqlnd_qc.cache_by_default = 1</a></em> It is recommended to use the PHP constant <em><a href="mysqlnd-qc.constants.html" class="link">MYSQLND_QC_DISABLE_SWITCH</a></em> instead of using the string value. </p> <p class="para"> <div class="example" id="example-1847"> <p><strong>Example #2 Using the <em>MYSQLND_QC_DISABLE_SWITCH</em> SQL hint</strong></p> <div class="example-contents"> <div class="inicode"><pre class="inicode">mysqlnd_qc.enable_qc=1 mysqlnd_qc.cache_by_default=1</pre> </div> </div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Connect, create and populate test table */<br /></span><span style="color: #0000BB">$mysqli </span><span style="color: #007700">= new </span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"host"</span><span style="color: #007700">, </span><span style="color: #DD0000">"user"</span><span style="color: #007700">, </span><span style="color: #DD0000">"password"</span><span style="color: #007700">, </span><span style="color: #DD0000">"schema"</span><span style="color: #007700">, </span><span style="color: #DD0000">"port"</span><span style="color: #007700">, </span><span style="color: #DD0000">"socket"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP TABLE IF EXISTS test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE TABLE test(id INT)"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO test(id) VALUES (1), (2)"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Will be cached although no SQL hint is present because of mysqlnd_qc.cache_by_default = 1*/<br /></span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT id FROM test WHERE id = 1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">free</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"DELETE FROM test WHERE id = 1"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Cache hit - no automatic invalidation and still valid! */<br /></span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT id FROM test WHERE id = 1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">free</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* Cache miss - query must not be cached because of the SQL hint */<br /></span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"/*" </span><span style="color: #007700">. </span><span style="color: #0000BB">MYSQLND_QC_DISABLE_SWITCH </span><span style="color: #007700">. </span><span style="color: #DD0000">"*/SELECT id FROM test WHERE id = 1"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">free</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above examples will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> array(1) { ["id"]=> string(1) "1" } array(1) { ["id"]=> string(1) "1" } NULL </pre></div> </div> </div> </p> <p class="para"> PECL/mysqlnd_qc forbids caching of statements for which at least one column from the statements result set shows no table name in its meta data by default. This is usually the case for columns originating from SQL functions such as <em>NOW()</em> or <em>LAST_INSERT_ID()</em>. The policy aims to prevent pitfalls if caching by default is used. </p> <p class="para"> <div class="example" id="example-1848"> <p><strong>Example #3 Example showing which type of statements are not cached</strong></p> <div class="example-contents"> <div class="inicode"><pre class="inicode">mysqlnd_qc.enable_qc=1 mysqlnd_qc.cache_by_default=1</pre> </div> </div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Connect, create and populate test table */<br /></span><span style="color: #0000BB">$mysqli </span><span style="color: #007700">= new </span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"host"</span><span style="color: #007700">, </span><span style="color: #DD0000">"user"</span><span style="color: #007700">, </span><span style="color: #DD0000">"password"</span><span style="color: #007700">, </span><span style="color: #DD0000">"schema"</span><span style="color: #007700">, </span><span style="color: #DD0000">"port"</span><span style="color: #007700">, </span><span style="color: #DD0000">"socket"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP TABLE IF EXISTS test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE TABLE test(id INT)"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO test(id) VALUES (1)"</span><span style="color: #007700">);<br /><br />for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">< </span><span style="color: #0000BB">3</span><span style="color: #007700">; </span><span style="color: #0000BB">$i</span><span style="color: #007700">++) {<br /><br /> </span><span style="color: #0000BB">$start </span><span style="color: #007700">= </span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /> </span><span style="color: #FF8000">/* Note: statement will not be cached because of NOW() use */<br /> </span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT id, NOW() AS _time FROM test"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">();<br /><br /> </span><span style="color: #FF8000">/* dump results */<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$row</span><span style="color: #007700">);<br /><br /> </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Total time: %.6fs\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">) - </span><span style="color: #0000BB">$start</span><span style="color: #007700">);<br /><br /> </span><span style="color: #FF8000">/* pause one second */<br /> </span><span style="color: #0000BB">sleep</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above examples will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> array(2) { ["id"]=> string(1) "1" ["_time"]=> string(19) "2012-01-11 15:43:10" } Total time: 0.000540s array(2) { ["id"]=> string(1) "1" ["_time"]=> string(19) "2012-01-11 15:43:11" } Total time: 0.000555s array(2) { ["id"]=> string(1) "1" ["_time"]=> string(19) "2012-01-11 15:43:12" } Total time: 0.000549s </pre></div> </div> </div> </p> <p class="para"> It is possible to enable caching for all statements including those which has columns in their result set for which MySQL reports no table, such as the statement from the example. Set <a href="mysqlnd-qc.configuration.html#ini.mysqlnd-qc.cache-no-table" class="link"><em>mysqlnd_qc.cache_no_table = 1</em></a> to enable caching of such statements. Please, note the difference in the measured times for the above and below examples. </p> <p class="para"> <div class="example" id="example-1849"> <p><strong>Example #4 Enabling caching for all statements using the <em>mysqlnd_qc.cache_no_table</em> ini setting</strong></p> <div class="example-contents"> <div class="inicode"><pre class="inicode">mysqlnd_qc.enable_qc=1 mysqlnd_qc.cache_by_default=1 mysqlnd_qc.cache_no_table=1</pre> </div> </div> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* Connect, create and populate test table */<br /></span><span style="color: #0000BB">$mysqli </span><span style="color: #007700">= new </span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"host"</span><span style="color: #007700">, </span><span style="color: #DD0000">"user"</span><span style="color: #007700">, </span><span style="color: #DD0000">"password"</span><span style="color: #007700">, </span><span style="color: #DD0000">"schema"</span><span style="color: #007700">, </span><span style="color: #DD0000">"port"</span><span style="color: #007700">, </span><span style="color: #DD0000">"socket"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP TABLE IF EXISTS test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE TABLE test(id INT)"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"INSERT INTO test(id) VALUES (1)"</span><span style="color: #007700">);<br /><br />for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">< </span><span style="color: #0000BB">3</span><span style="color: #007700">; </span><span style="color: #0000BB">$i</span><span style="color: #007700">++) {<br /><br /> </span><span style="color: #0000BB">$start </span><span style="color: #007700">= </span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /> </span><span style="color: #FF8000">/* Note: statement will not be cached because of NOW() use */<br /> </span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-></span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT id, NOW() AS _time FROM test"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">$res</span><span style="color: #007700">-></span><span style="color: #0000BB">fetch_assoc</span><span style="color: #007700">();<br /><br /> </span><span style="color: #FF8000">/* dump results */<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$row</span><span style="color: #007700">);<br /><br /> </span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"Total time: %.6fs\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">) - </span><span style="color: #0000BB">$start</span><span style="color: #007700">);<br /><br /> </span><span style="color: #FF8000">/* pause one second */<br /> </span><span style="color: #0000BB">sleep</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above examples will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> array(2) { ["id"]=> string(1) "1" ["_time"]=> string(19) "2012-01-11 15:47:45" } Total time: 0.000546s array(2) { ["id"]=> string(1) "1" ["_time"]=> string(19) "2012-01-11 15:47:45" } Total time: 0.000187s array(2) { ["id"]=> string(1) "1" ["_time"]=> string(19) "2012-01-11 15:47:45" } Total time: 0.000167s </pre></div> </div> </div> </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Although <a href="mysqlnd-qc.configuration.html#ini.mysqlnd-qc.cache-no-table" class="link"><em>mysqlnd_qc.cache_no_table = 1</em></a> has been created for use with <em><a href="mysqlnd-qc.configuration.html" class="link">mysqlnd_qc.cache_by_default = 1</a></em> it is bound it. The plugin will evaluate the <a href="mysqlnd-qc.configuration.html#ini.mysqlnd-qc.cache-no-table" class="link"><em>mysqlnd_qc.cache_no_table</em></a> whenever a query is to be cached, no matter whether caching has been enabled using a SQL hint or any other measure. </p> </p></blockquote> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mysqlnd-qc.quickstart.configuration.html">Setup</a></div> <div class="next" style="text-align: right; float: right;"><a href="mysqlnd-qc.per-query-ttl.html">Setting the TTL</a></div> <div class="up"><a href="mysqlnd-qc.quickstart.html">Quickstart and Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>