Example #1 memcache锟斤拷展锟斤拷锟斤拷示锟斤拷

锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷校锟揭伙拷锟斤拷锟斤拷蟊槐锟斤拷娴斤拷锟斤拷锟斤拷校锟斤拷直锟饺★拷亍锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟角憋拷锟斤拷锟斤拷锟斤拷锟节存储 之前锟斤拷锟饺憋拷锟斤拷锟叫伙拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷娲拷锟皆达拷锟斤拷停锟斤拷锟斤拷颖锟角硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷注锟斤拷锟斤拷注锟斤拷锟斤拷式锟斤拷 锟斤拷源锟斤拷锟酵存储锟斤拷锟斤拷锟斤拷要锟斤拷锟斤拷亩锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟皆达拷锟斤拷锟斤拷锟斤拷锟侥筹拷锟斤拷锟斤拷锟饺达拷锟斤拷锟皆达拷锟�

<?php

$memcache 
= new Memcache;
$memcache->connect('localhost'11211) or die ("Could not connect");

$version $memcache->getVersion();
echo 
"锟斤拷锟斤拷税姹撅拷锟较�: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr 'test';
$tmp_object->int_attr 123;

$memcache->set('key'$tmp_objectfalse10) or die ("Failed to save data at the server");
echo 
"锟斤拷锟斤拷锟捷憋拷锟芥到锟斤拷锟斤拷锟叫o拷锟斤拷锟斤拷10锟斤拷锟绞э拷锟�<br/>\n";

$get_result $memcache->get('key');
echo 
"锟接伙拷锟斤拷锟斤拷取锟斤拷锟斤拷锟斤拷锟斤拷:<br/>\n";

var_dump($get_result);

?>

Example #2 使锟斤拷memcache锟斤拷session锟斤拷锟斤拷锟斤拷

<?php

$session_save_path 
"tcp://$host:$port?persistent=1&weight=2&timeout=2&retry_interval=10,  ,tcp://$host:$port  ";
ini_set('session.save_handler''memcache');
ini_set('session.save_path'$session_save_path);

?>