Home > Backend Development > PHP Tutorial > PHP uses memcache to store session method summary, memcachesession_PHP tutorial

PHP uses memcache to store session method summary, memcachesession_PHP tutorial

WBOY
Release: 2016-07-12 09:00:47
Original
1013 people have browsed it

php uses memcache to store session method summary, memcachesession

set session to use memcache to store

Method I: Set globally in php.ini
session.save_handler = memcache
session.save_path = "tcp://127.0.0.1:11211"


Method II: .htaccess in a certain directory
php_value session.save_handler "memcache"
php_value session.save_path "tcp://127.0.0.1:11211"


Method III: Or in a certain application

1 ini_set("session.save_handler", "memcache"); 
2 ini_set("session.save_path", "tcp://127.0.0.1:11211");
Copy after login



When using multiple memcached servers, separate them with commas ",", and as explained in the Memcache::addServer() document, you can take additional parameters "persistent", "weight", "timeout", "retry_interval" " Wait, something like this: "tcp://host1:port1?persistent=1&weight=2,tcp://host2:port2".

If the installed PECL is memcached (the extension that relies on the libmemcached library), the configuration should be
Php code collection code
ini_set("session.save_handler", "memcached"); // It is 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)

PHP uses memcache to store session method summary, memcachesession_PHP tutorial
 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']; 
10 print "<br><br>"; 
11 print $_SESSION['TEST3']; 
12 print "<br><br>"; 
13 print session_id(); 
14 ?>
Copy after login
PHP uses memcache to store session method summary, memcachesession_PHP tutorial

Use sessionid to check in memcached:

?
1 2 3 4 5 6 <?php $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;"
Output like this proves that the session is working normally.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1091270.htmlTechArticlephp uses memcache to store session method summary, memcachesession setting session uses memcache to store method I: in php.ini Globally set session.save_handler = memcache session.s...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template