Memcache Storing PHP session
set session with Memcache to store ?
method I: Global settings in php.ini ?
PHP.ini code??
- Session.save_handler?=?memcache??
- Session.save_path?=? "tcp://127.0.0.1:11211"??
Method II: In a directory. htaccess ?
PHP.ini code??
- Php_value?session.save_handler? "Memcache"??
- Php_value?session.save_path?? "tcp://127.0.0.1:11211"??
Method III: Again or in one application ?
PHP code??
- Ini_set ("Session.save_handler",? "Memcache");??
- 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 (the one that relies on the libmemcached library), then the configuration should be?
PHP code??
- ini_set ( " Session.save_handler ",? "memcached" );? //? memcached, not Memcach. E ??
- Ini_set ("Session.save_path",? "127.0.0.1:11211");? //? Do not tcp:[/b]??
code example (the one that does not depend on the libmemcached library) ?
PHP code??
-
- Session_Start ();??
- if? (!isset ($_session[' TEST ']))? {??
- ???? $_session [' TEST ']?=?time ();??
- }??
- ???
- $_session [' TEST3 ']?=?time ();??
- ???
- Print? $_session [' TEST '];??
- Print? "
";??
- Print? $_session [' TEST3 '];??
- Print? "
";??
- PRINT?SESSION_ID ();??
- ???
use SessionID to memcached to inquire about:?
PHP code??
-
- $memcache? =?memcache_connect (' localhost ',? 11211);??
- Var_dump ($memcache->get (' 19216821213c65cedec65b0883238c278eeb573e077 '));??
- $memcache->set (' aaaa ',?') Hello?everyone ');??
- Var_dump ($memcache->get (' aaaa '));??
- ???
Will see?
String (PNS) "test|i:1177556731; test3|i:1177556881; "?
This output proves that the session is working properly.
?