Php uses memcache to store the session method Summary set the session uses memcache to store the method I: in php. set the session globally in ini. save_handlermemcachesession.save_pathtcp: 127.0.0.1: 11211 Method II: Under a directory. htaccessphp _ php use memcache to store the session method summary
Set the session to use memcache for storage
Method I: global settings in php. ini
Session. save_handler = memcache
Session. save_path = "tcp: // fig: 11211"
Method II:. htaccess under a directory
Php_value session. save_handler "memcache"
Php_value session. save_path "tcp: // fig: 11211"
Method III: or in an application
1 ini_set("session.save_handler", "memcache"); 2 ini_set("session.save_path", "tcp://127.0.0.1:11211");
Multiple memcached servers are separated by commas (,), which are the same as those described in the Memcache: addServer () document, you can include additional parameters such as "persistent", "weight", "timeout", and "retry_interval". for example, "tcp: // host1: port1? Persistent = 1 & weight = 2, tcp: // host2: port2 ".
If the installed PECL is memcached (the extension dependent on the libmemcached Library), the configuration should be
Add Php code to favorites
Ini_set ("session. save_handler", "memcached"); // it indicates that memcached is not memcache.
Ini_set ("session. save_path", "127.0.0.1: 11211"); // do not use tcp: [/B]
Code example (not dependent on the libmemcached Library)
1
"; 11 print $_SESSION['TEST3']; 12 print "
"; 13 print session_id(); 14 ?>
Use sessionid to query in memcached:
?
1 2 3 4 5 6 |
$memcache = memcache_connect( 'localhost' , 11211);
var_dump( $memcache ->get( '19216821213c65cedec65b0883238c278eeb573e077' ));
$memcache ->set( 'aaaa' , 'hello everyone' );
var_dump( $memcache ->get( 'aaaa' ));
?>
|
You will see
String (37) "TEST | I: 1177556731; TEST3 | I: 1177556881 ;"
This output proves that the session works normally.