session是php中一个服务器端超级全局变量而memcache是缓存应用,下面我来把它们整合起来把session存放在memcache中,下面我们一起来看如何实现的吧。
1.首先安装memcached或者memcache软件
参考:wamp 安装 memcache/memcached详细说明
2.安装php_memcache.dll扩展
3.设置session保存在memcached
方法一:
修改php.ini文件
session.save_handler = memcache session.save_path = "tcp://127.0.0.1:11211"
方法二:
程序中动态设置
ini_set("session.save_handler", "memcache"); ini_set("session.save_path", "tcp://127.0.0.1:11211");
测试程序
1.session.php
2.test.php
<?php // memcache test code $memcache = new Memcache; //创建一个memcache对象 $memcache->connect('127.0.0.1', 11211) or die("Could not connect"); //连接Memcached服务器 print_r($memcache->get('5d3d79d7500f5836033e9019b3eefc6f')); //username|s:9:"phpff.com"; ?>
文章链接:
随便收藏,请保留本文地址!
Statement
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
4 weeks agoByDDD
R.E.P.O. Save File Location: Where Is It & How to Protect It?
4 weeks agoByDDD

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 English version
Recommended: Win version, supports code prompts!
