php-扩展mysqlnd_qc的应用

一般来说,当mysql一个实例不够用的时候,常见的方式是mysql集群架构。对于多读的场景,如果数据不经常变的话,可以用memcached来做缓
存。

现在php提供一个缓存的扩展.mysqlnd_qc.

1:启用mysqlnd_qc.修改php.ini

mysqlnd_qc.enable_qc=1

2:缓存查询

<?php
/* 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)");

/* Will be cached because of the SQL hint */
$start = microtime(true);
$res   = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 1");

var_dump($res->fetch_assoc());
$res->free();

printf("Total time uncached query: %.6fs\n", microtime(true) - $start);

/* Cache hit */
$start = microtime(true);
$res   = $mysqli->query("/*" . MYSQLND_QC_ENABLE_SWITCH . "*/" . "SELECT id FROM test WHERE id = 1");

var_dump($res->fetch_assoc());
$res->free();

printf("Total time cached query: %.6fs\n", microtime(true) - $start);

更多见:http://php.net/mysqlnd_qc

and especially this all work really nicely
christina aguilera weight loss Red Hat’s Management Presents Storage Technologies Update Call Transcript

I’d made a deal with one farmer
gay pornStrong Business Of Well Known Brands Worthy Of Your Portfolio
large porn tube
此条目发表在 网站开发 分类目录。将固定链接加入收藏夹。

评论功能已关闭。