安裝 NMP-Server
安裝 memcached-1.2.6
複製 php_memcache.dll 檔案到php ext
修改 mod php.ini
--新增 php_memcache.dll extension
--設定 [memcache]
[memcache]
memcache.hash_strategy = consistent
memcache.chunk_size = 32768
refer
http://winson111.blogspot.com/2010/01/php-memcached.html
http://drcarter.info/tag/memcached/
http://blog.wu-boy.com/2007/09/freebsd-%E5%AE%89%E8%A3%9D-memcache-for-php/
http://wiki.nginx.org/HttpMemcachedModule
http://wpadm.com/p/154.html
測試程式碼
/*
$memcache = new Memcache;
$memcache->connect("localhost",11211); # You might need to set "localhost" to "127.0.0.1"
echo "Server's version: " . $memcache->getVersion() . "
\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = "中文";
$tmp_object->int_attr = 123;
$memcache->set("key",$tmp_object,false,10);
echo "Store data in the cache (data will expire in 10 seconds)
\n";
echo "Data from the cache:
\n";
var_dump($memcache->get("key"));
*/
$memcache = new Memcache;
$memcache->addServer('localhost', 11211);
$memcache->addServer('localhost', 11212);
$memcache->addServer('localhost', 11213);
$tmp_object = new stdClass;
for($i=0; $i<102400; $i++) {
$user_id = getRandomString();
$tmp_object->str_attr = getRandomString()."中文";
$tmp_object->int_attr = mt_rand(0, 10240000);
$sql = "SELECT * FROM user WHERE user_id = ?";
$key = 'SQL:' . $user_id . ':' . md5($sql);
$memcache->set( $key , $tmp_object , false , 3600 );
//echo "Store data in the cache (data will expire in 3600 seconds)
\n";
//echo "Data from the cache:
\n";
print_r($memcache->get($key));echo "
\n";
}
$memStats = $memcache->getExtendedStats();
print_r($memStats);
function getRandomString($length = 6) {
$validCharacters = "abcdefghijklmnopqrstuxyvwzABCDEFGHIJKLMNOPQRSTUXYVWZ+-*#&@!?";
$validCharNumber = strlen($validCharacters);
$result = "";
for ($i = 0; $i < $length; $i++) {
$index = mt_rand(0, $validCharNumber - 1);
$result .= $validCharacters[$index];
}
return $result;
}
?>
安裝 memcached-1.2.6
複製 php_memcache.dll 檔案到php ext
修改 mod php.ini
--新增 php_memcache.dll extension
--設定 [memcache]
[memcache]
memcache.hash_strategy = consistent
memcache.chunk_size = 32768
refer
http://winson111.blogspot.com/2010/01/php-memcached.html
http://drcarter.info/tag/memcached/
http://blog.wu-boy.com/2007/09/freebsd-%E5%AE%89%E8%A3%9D-memcache-for-php/
http://wiki.nginx.org/HttpMemcachedModule
http://wpadm.com/p/154.html
測試程式碼
/*
$memcache = new Memcache;
$memcache->connect("localhost",11211); # You might need to set "localhost" to "127.0.0.1"
echo "Server's version: " . $memcache->getVersion() . "
\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = "中文";
$tmp_object->int_attr = 123;
$memcache->set("key",$tmp_object,false,10);
echo "Store data in the cache (data will expire in 10 seconds)
\n";
echo "Data from the cache:
\n";
var_dump($memcache->get("key"));
*/
$memcache = new Memcache;
$memcache->addServer('localhost', 11211);
$memcache->addServer('localhost', 11212);
$memcache->addServer('localhost', 11213);
$tmp_object = new stdClass;
for($i=0; $i<102400; $i++) {
$user_id = getRandomString();
$tmp_object->str_attr = getRandomString()."中文";
$tmp_object->int_attr = mt_rand(0, 10240000);
$sql = "SELECT * FROM user WHERE user_id = ?";
$key = 'SQL:' . $user_id . ':' . md5($sql);
$memcache->set( $key , $tmp_object , false , 3600 );
//echo "Store data in the cache (data will expire in 3600 seconds)
\n";
//echo "Data from the cache:
\n";
print_r($memcache->get($key));echo "
\n";
}
$memStats = $memcache->getExtendedStats();
print_r($memStats);
function getRandomString($length = 6) {
$validCharacters = "abcdefghijklmnopqrstuxyvwzABCDEFGHIJKLMNOPQRSTUXYVWZ+-*#&@!?";
$validCharNumber = strlen($validCharacters);
$result = "";
for ($i = 0; $i < $length; $i++) {
$index = mt_rand(0, $validCharNumber - 1);
$result .= $validCharacters[$index];
}
return $result;
}
?>
文章標籤
全站熱搜
留言列表