Set session with Memcache to store
Method I: Global settings in php.ini
Session.save_handler = Memcache
Session.save_path = "tcp://127.0.0.1:11211"
Method II: In a directory. htaccess
Php_value Session.save_handler "Memcache"
Php_value Session.save_path "tcp://127.0.0.1:11211"
Method III: Again or in one application
1 Ini_set ("Session.save_handler", "memcache"); 2 Ini_set ("Session.save_path", "tcp://127.0.0.1:11211");
Use multiple memcached servers separated by commas "," and, as described in the memcache::addserver () documentation, can take additional parameters "persistent", "weight", "timeout", "Retry_ Interval "And so on, like this:" Tcp://host1:port1?persistent=1&weight=2,tcp://host2:port2 ".
If the installed pecl is memcached (which relies on the extension of the libmemcached library), the configuration should be
PHP Code Collection Code
Ini_set ("Session.save_handler", "memcached"); It's memcached, not memcache.
Ini_set ("Session.save_path", "127.0.0.1:11211"); Don't tcp:[/b]
code example (the one that does not depend on the libmemcached library)
1 <?php 2 session_start (); 3 if (!isset ($_session[' test ')) { 4 $_session[' test '] = time (); 5} 6 7 $_session[' TEST3 ' = Time (); 8 9 Print $_session[' TEST '; print "<br><br>"; print $_session[' TEST3 "; print" <br><br > "; Print session_id (); ?>
Use SessionID to go to memcached to check:
?
123456 |
<?php $memcache = memcache_connect ( ' localhost ' var_dump ( $memcache ->get ( ' 19216821213c65cedec65b0883238c278eeb573e077 ' $memcache ->set ( ' AAAA ' ' Hello everyone ' ); var_dump ( $memcache ->get ( ' aaaa ' ?> |
'll see
String (PNS) "test|i:1177556731; test3|i:1177556881; "
This output proves that the session is working properly.
PHP uses Memcache to store session method summary