In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the configuration methods of using memcache to store session in PHP", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the configuration methods of using memcache to store session in PHP?"
1. Modify the php.ini configuration file directly
The copy code is as follows:
Session.save_handler = memcache / / set the storage mode of session to memcache
Memcache.hash_strategy = "consistent" / / sets the hash algorithm for memcache
Session.save_path = "tcp://127.0.0.100:11211" / / sets the location where session is stored, and multiple memcache are separated by commas, for example: tcp://127.0.0.1:11211,tcp://127.0.0.1:12000
2. Configure using the .htaccess file in the directory
The copy code is as follows:
Php_value session.save_handler "memcache"
Php_value session.save_path "tcp://127.0.0.1:11211"
Note: this is only for Apache. At present, many people use Nginx, and this method is not recommended.
3. Modify the configuration in the PHP file of the project
The copy code is as follows:
Ini_set ("session.save_handler", "memcache")
Ini_set ("session.save_path", "tcp://127.0.0.100:11211")
4. Test examples
The copy code is as follows:
/ / Test whether the session read is normal
Session_start ()
$_ SESSION ['username'] = "jb51.net"
Echo session_id ()
/ / read session from Memcache
M = new Memcache ()
M-> connect ('localhost', 11211)
/ / or this
/ / $mem- > addServer ("127.0.0.1", 11211) or die ("Can't add Memcache server 127.0.0.1 or die")
/ / obtain data according to session_id
/ / this machine
/ / $session = $m-> get (session_id ()); / / session_id:d527b6f983bd5e941f9fff318a31206b
/ / another server, known session id
$session = $m-> get ("d527b6f983bd5e941f9fff318a31206b")
Echo $session. ""; / / you will get the following data: username | Svv 16: "pandao";, you can get the corresponding value by parsing it.
Echo session_id (). "
Exit
At this point, I believe you have a deeper understanding of "what are the configuration methods of using memcache to store session in PHP?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.