21.5 memcached命令行

Memcached语法规则:

1. <command name> <key> <flags> <exptime> <bytes>\r\n <data block>\r\n

注:\r\n在windows下是Enter

2. <command name> 可以是set, add, replace

3. set表示按照相应的<key>存储该数据,没有的时候增加,有的时候覆盖

4. add表示按照相应的<key>添加该数据,但是如果该<key>已经存在则会操作失败

5. replace表示按照相应的<key>替换数据,但是如果该<key>不存在则操作失败。

6. <key> 客户端需要保存数据的key

7.  <flags> 是一个16位的无符号的整数(以十进制的方式表示)。该标志将和需要存储的数据一起存储,并在客户端get数据时返回。客户端可以将此标志用做特殊用途,此标志对服务器来说是不透明的。

8. <exptime> 为过期的时间。若为0表示存储的数据永远不过期(但可被服务器算法:LRU 等替换)。如果非0(unix时间或者距离此时的秒数),当过期后,服务器可以保证用户得不到该数据(以服务器时间为标准)。

9. <bytes> 需要存储的字节数,当用户希望存储空数据时<bytes>可以为0

10. <data block>需要存储的内容,输入完成后,最后客户端需要加上\r\n(直接点击Enter)作为结束标志。

启动

[root@aminglinux-149 ~]# systemctl start memcached

1. 安装telnet

[root@aminglinux-149 ~]# yum install -y telnet

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * epel: mirrors.aliyun.com

 * extras: mirrors.neusoft.edu.cn

 * updates: mirrors.neusoft.edu.cn

软件包 1:telnet-0.17-64.el7.x86_64 已安装并且是最新版本

无须任何处理

2. telnet 指定ip 端口进入telnet界面

[root@aminglinux-149 ~]# telnet 127.0.0.1 11211

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is '^]'.

set key1 0 30 5

12345

2.jpg

查看key1存储的内容(查看超出了存储时间,会查不到的)

get key1  

END

提示:在telnet模式下,退格键需要按住Ctrl键

实验案例:

设定key1flags1 120秒到期时间 4个存储字节

set key1 1 120 4    

1234

STORED

替换key1flags1 0为不限制时间 6个存储字节

replace key1 1 0 6

123456

NOT_STORED

查看key1的值

get key1

END

删除key1的值

delete key1

NOT_FOUND

 

21.6 memcached数据导出和导入

1. 导出memcached数据:

[root@aminglinux-149 ~]# memcached-tool 127.0.0.1:11211 dump

Dumping memcache contents

  Number of buckets: 0

  Number of items  :

3.jpg

2. 导出memcached数据,重定向到指定文件data.txt内:

[root@aminglinux-149 ~]# memcached-tool 127.0.0.1:11211 dump > data.txt

3. 重启memcached

(清理之前存储的数据,为了导入已存在的数据会不被覆盖的)

[root@aminglinux-149 ~]# systemctl restart memcached

4. data.txt导入到memcached

[root@aminglinux-149 ~]# nc 127.0.01 11211 < data.txt

若nc命令不存在,yum install nc

注意:导出的数据是带有一个时间戳的,这个时间戳就是该条数据过期的时间点,如果当前时间已经超过该时间戳,那么是导入不进去的

21.7 php连接memcached

1. /...src/目录下,下memcache

[root@aminglinux-149 ~]# cd /usr/local/src/
[root@aminglinux-149 src]# wget http://×××w.apelearn.com/bbs/data/attachment/forum/memcache-2.2.3.tgz
--2018-11-24 17:48:01--  http://×××w.apelearn.com/bbs/data/attachment/forum/memcache-2.2.3.tgz
正在解析主机 ×××w.apelearn.com (×××w.apelearn.com)... 47.104.7.242
正在连接 ×××w.apelearn.com (×××w.apelearn.com)|47.104.7.242|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:27366 (27K) [application/octet-stream]
正在保存至: “memcache-2.2.3.tgz”
100%[==============================================>] 27,366      --.-K/s 用时 0.06s  
2018-11-24 17:48:02 (462 KB/s) - 已保存 “memcache-2.2.3.tgz” [27366/27366])
[root@aminglinux-149 src]# tar zxvf memcache-2.2.3.tgz
package.xml
memcache-2.2.3/config.m4
memcache-2.2.3/config9.m4
memcache-2.2.3/config.w32
memcache-2.2.3/CREDITS
memcache-2.2.3/example.php
memcache-2.2.3/memcache.c
memcache-2.2.3/memcache_queue.c
memcache-2.2.3/memcache_session.c
memcache-2.2.3/memcache_standard_hash.c
memcache-2.2.3/memcache_consistent_hash.c
memcache-2.2.3/memcache.dsp
memcache-2.2.3/php_memcache.h
memcache-2.2.3/memcache_queue.h
memcache-2.2.3/README
[root@aminglinux-149 src]# cd memcache-2.2.3
[root@aminglinux-149 memcache-2.2.3]#  yum install -y autoconf
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                             | 3.5 kB  00:00:00     
 * base: mirrors.aliyun.com
 * epel: ftp.yz.yamagata-u.ac.jp
 * extras: mirrors.neusoft.edu.cn
 * updates: mirrors.neusoft.edu.cn
base                                                             | 3.6 kB  00:00:00     
epel                                                             | 3.2 kB  00:00:00     
extras 
[root@aminglinux-149 memcache-2.2.3]# /usr/local/php-fpm/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
[root@aminglinux-149 memcache-2.2.3]# ./configure --with-php-config=/usr/local/php-fpm/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php-fpm
checking for PHP includes... -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php-fpm/lib/php/extensions/no-debug-non-zts-20131226
checking for PHP installed headers prefix... /usr/local/php-fpm/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable memcache support... yes, shared
checking whether to enable memcache session handler support... yes
checking for the location of ZLIB... no
checking for the location of zlib... /usr
checking for session includes... /usr/local/php-fpm/include/php
checking for memcache session support... enabled
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
[root@aminglinux-149 memcache-2.2.3]# echo $?
0
[root@aminglinux-149 memcache-2.2.3]# make && make install 
/bin/sh /usr/local/src/memcache-2.2.3/libtool --mode=compile cc -I/usr/local/php-fpm/include/php -I. -I/usr/local/src/memcache-2.2.3 -DPHP_ATOM_INC -I/usr/local/src/memcache-2.2.3/include -I/usr/local/src/memcache-2.2.3/main -I/usr/local/src/memcache-2.2.3 -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/memcache-2.2.3/memcache.c -o memcache.lo 
mkdir .libs
 cc -I/usr/local/php-fpm/include/php -I. -I/usr/local/src/memcache-2.2.3 -DPHP_ATOM_INC -I/usr/local/src/memcache-2.2.3/include -I/usr/local/src/memcache-2.2.3/main -I/usr/local/src/memcache-2.2.3 -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/memcache-2.2.3/memcache.c  -fPIC -DPIC -o .libs/memcache.o
/usr/local/src/memcache-2.2.3/memcache.c: 在函数‘mmc_str_left’中:
/usr/local/src/memcache-2.2.3/memcache.c:1116:8: 警告:assignment discards ‘const’ qualifier from pointer target type [默认启用]
  found = php_memnstr(haystack, needle, needle_len, haystack + haystack_len);
        ^
/usr/local/src/memcache-2.2.3/memcache.c: 在函数‘mmc_stats_parse_stat’中:
/usr/local/src/memcache-2.2.3/memcache.c:1523:13: 警告:assignment discards ‘const’ qualifier from pointer target type [默认启用]
  if ((space = php_memnstr(start, " ", 1, end)) == NULL) {
             ^
/usr/local/src/memcache-2.2.3/memcache.c:1528:13: 警告:assignment discards ‘const’ qualifier from pointer target type [默认启用]
  if ((colon = php_memnstr(start, ":", 1, space - 1)) != NULL) {
             ^
/usr/local/src/memcache-2.2.3/memcache.c: 在函数‘mmc_stats_parse_item’中:
/usr/local/src/memcache-2.2.3/memcache.c:1566:13: 警告:assignment discards ‘const’ qualifier from pointer target type [默认启用]
  if ((space = php_memnstr(start, " ", 1, end)) == NULL) {
             ^
/usr/local/src/memcache-2.2.3/memcache.c:1574:13: 警告:assignment discards ‘const’ qualifier from pointer target type [默认启用]
  for (value = php_memnstr(space, "[", 1, end); value != NULL && value <= end; value = php_memnstr(value + 1, ";", 1, end)) {
             ^
/usr/local/src/memcache-2.2.3/memcache.c:1574:85: 警告:assignment discards ‘const’ qualifier from pointer target type [默认启用]
  for (value = php_memnstr(space, "[", 1, end); value != NULL && value <= end; value = php_memnstr(value + 1, ";", 1, end)) {
                                                                                     ^
/usr/local/src/memcache-2.2.3/memcache.c:1579:34: 警告:assignment discards ‘const’ qualifier from pointer target type [默认启用]
   if (value <= end && (value_end = php_memnstr(value, " ", 1, end)) != NULL && value_end <= end) {
                                  ^
/usr/local/src/memcache-2.2.3/memcache.c: 在函数‘mmc_stats_parse_generic’中:
/usr/local/src/memcache-2.2.3/memcache.c:1603:14: 警告:assignment discards ‘const’ qualifier from pointer target type [默认启用]
   if ((space = php_memnstr(start, " ", 1, end)) != NULL) {
              ^
/bin/sh /usr/local/src/memcache-2.2.3/libtool --mode=compile cc -I/usr/local/php-fpm/include/php -I. -I/usr/local/src/memcache-2.2.3 -DPHP_ATOM_INC -I/usr/local/src/memcache-2.2.3/include -I/usr/local/src/memcache-2.2.3/main -I/usr/local/src/memcache-2.2.3 -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/memcache-2.2.3/memcache_queue.c -o memcache_queue.lo 
 cc -I/usr/local/php-fpm/include/php -I. -I/usr/local/src/memcache-2.2.3 -DPHP_ATOM_INC -I/usr/local/src/memcache-2.2.3/include -I/usr/local/src/memcache-2.2.3/main -I/usr/local/src/memcache-2.2.3 -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/memcache-2.2.3/memcache_queue.c  -fPIC -DPIC -o .libs/memcache_queue.o
/bin/sh /usr/local/src/memcache-2.2.3/libtool --mode=compile cc -I/usr/local/php-fpm/include/php -I. -I/usr/local/src/memcache-2.2.3 -DPHP_ATOM_INC -I/usr/local/src/memcache-2.2.3/include -I/usr/local/src/memcache-2.2.3/main -I/usr/local/src/memcache-2.2.3 -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/memcache-2.2.3/memcache_standard_hash.c -o memcache_standard_hash.lo 
 cc -I/usr/local/php-fpm/include/php -I. -I/usr/local/src/memcache-2.2.3 -DPHP_ATOM_INC -I/usr/local/src/memcache-2.2.3/include -I/usr/local/src/memcache-2.2.3/main -I/usr/local/src/memcache-2.2.3 -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/memcache-2.2.3/memcache_standard_hash.c  -fPIC -DPIC -o .libs/memcache_standard_hash.o
/bin/sh /usr/local/src/memcache-2.2.3/libtool --mode=compile cc -I/usr/local/php-fpm/include/php -I. -I/usr/local/src/memcache-2.2.3 -DPHP_ATOM_INC -I/usr/local/src/memcache-2.2.3/include -I/usr/local/src/memcache-2.2.3/main -I/usr/local/src/memcache-2.2.3 -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/memcache-2.2.3/memcache_consistent_hash.c -o memcache_consistent_hash.lo 
 cc -I/usr/local/php-fpm/include/php -I. -I/usr/local/src/memcache-2.2.3 -DPHP_ATOM_INC -I/usr/local/src/memcache-2.2.3/include -I/usr/local/src/memcache-2.2.3/main -I/usr/local/src/memcache-2.2.3 -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/memcache-2.2.3/memcache_consistent_hash.c  -fPIC -DPIC -o .libs/memcache_consistent_hash.o
/bin/sh /usr/local/src/memcache-2.2.3/libtool --mode=compile cc -I/usr/local/php-fpm/include/php -I. -I/usr/local/src/memcache-2.2.3 -DPHP_ATOM_INC -I/usr/local/src/memcache-2.2.3/include -I/usr/local/src/memcache-2.2.3/main -I/usr/local/src/memcache-2.2.3 -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/memcache-2.2.3/memcache_session.c -o memcache_session.lo 
 cc -I/usr/local/php-fpm/include/php -I. -I/usr/local/src/memcache-2.2.3 -DPHP_ATOM_INC -I/usr/local/src/memcache-2.2.3/include -I/usr/local/src/memcache-2.2.3/main -I/usr/local/src/memcache-2.2.3 -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/memcache-2.2.3/memcache_session.c  -fPIC -DPIC -o .libs/memcache_session.o
/bin/sh /usr/local/src/memcache-2.2.3/libtool --mode=link cc -DPHP_ATOM_INC -I/usr/local/src/memcache-2.2.3/include -I/usr/local/src/memcache-2.2.3/main -I/usr/local/src/memcache-2.2.3 -I/usr/local/php-fpm/include/php -I/usr/local/php-fpm/include/php/main -I/usr/local/php-fpm/include/php/TSRM -I/usr/local/php-fpm/include/php/Zend -I/usr/local/php-fpm/include/php/ext -I/usr/local/php-fpm/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -o memcache.la -export-dynamic -avoid-version -prefer-pic -module -rpath /usr/local/src/memcache-2.2.3/modules  memcache.lo memcache_queue.lo memcache_standard_hash.lo memcache_consistent_hash.lo memcache_session.lo 
cc -shared  .libs/memcache.o .libs/memcache_queue.o .libs/memcache_standard_hash.o .libs/memcache_consistent_hash.o .libs/memcache_session.o   -Wl,-soname -Wl,memcache.so -o .libs/memcache.so
creating memcache.la
(cd .libs && rm -f memcache.la && ln -s ../memcache.la memcache.la)
/bin/sh /usr/local/src/memcache-2.2.3/libtool --mode=install cp ./memcache.la /usr/local/src/memcache-2.2.3/modules
cp ./.libs/memcache.so /usr/local/src/memcache-2.2.3/modules/memcache.so
cp ./.libs/memcache.lai /usr/local/src/memcache-2.2.3/modules/memcache.la
PATH="$PATH:/sbin" ldconfig -n /usr/local/src/memcache-2.2.3/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/src/memcache-2.2.3/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions:     /usr/local/php-fpm/lib/php/extensions/no-debug-non-zts-20131226/
[root@aminglinux-149 memcache-2.2.3]# echo $?
0

6. make install 生成如下文件:

[root@aminglinux-149 memcache-2.2.3]# ls /usr/local/php-fpm/lib/php/extensions/no-debug-non-zts-20131226/

memcache.so  mongodb.so  opcache.a  opcache.so  redis.so

7. 编辑php-ini

[root@aminglinux-149 memcache-2.2.3]# vim /usr/local/php-fpm/etc/php-ini

8. 检查有没有memcache这个模块:

[root@aminglinux-149 memcache-2.2.3]# /usr/local/php-fpm/bin/php -m

[PHP Modules]

Core

ctype

curl

date

dom

ereg

exif

fileinfo

filter

ftp

gd

hash

iconv

json

libxml

mbstring

mcrypt

memcache

 21.8 memcached中存储session

1. 下载session存储脚本

[root@aminglinux-149 ~]# wget

2. 进入

[root@aminglinux-149 ~]# cd /data/wwwroot/

3. 移动session存储脚本,并重命名php格式脚本:

[root@aminglinux-149 test]# mv /root/.mem_se.txt  1.php

4. curl访问1.php

[root@aminglinux-149 test]# curl localhost/1.php

5. 查看tmp下有没有sess_格式的文件:

test]#  ls -lt /tmp/
总用量 0
srwxrwxrwx 1 mysql  mysql   0 11月 25 15:36 mysql.sock
srwx------ 1 mongod mongod  0 11月 25 15:36 mongodb-27017.sock
srw-rw-rw- 1 root   root    0 11月 25 15:36 php-fcgi.sock
drwx------ 3 root   root   60 11月 25 15:36 systemd-private-7e4b158a75c2468ea9d7a6d8a18ebd8e-httpd.service-Kc3wzD
drwx------ 3 root   root   60 11月 25 15:36 systemd-private-7e4b158a75c2468ea9d7a6d8a18ebd8e-cups.service-cQ0pZh
drwx------ 2 root   root   40 11月 25 15:36 vmware-root
drwx------ 3 root   root   60 11月 25 15:36 systemd-private-7e4b158a75c2468ea9d7a6d8a18ebd8e-chronyd.service-r2RXLD

 6. 编辑php-ini

vim /usr/local/php-fpm/etc/php-ini

注释掉这行:session.save_handler = files

添加:

session.save_handler = memcache session.save_path

"tcp://192.168.0.9:11211"

本实例是在lamp/lnmp环境下实现(下面哪种没问题,就用哪种)

1. 编辑php.ini添加两行

session.save_handler = memcache session.save_path

"tcp://192.168.0.9:11211" 

2. 或者httpd.conf中对应的虚拟主机中添加

php_value session.save_handler "memcache" php_value session.save_path "tcp://192.168.0.9:11211" 

3. 或者php-fpm.conf对应的pool中添加

php_value[session.save_handler] = memcache

php_value[session.save_path] = " tcp://192.168.0.9:11211 "

7. curl访问1.php

[root@hao-01 test.com]# curl localhost/1.php