目录标题
1. 什么是memcache
2. 操作
1. tar zxf memcache-4.0.5.2.tgz
2. vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin # 方便调用
export PATH
3. source ~/.bash_profile
4. cd memcache-4.0.5.2
5. yum install autoconf -y
6. phpize
7. ./configure --with-php-config=/usr/local/lnmp/php/bin/php-config
8. make && make install
/usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20190902/
cd /usr/local/lnmp/php/etc/
9. vim php.ini
759 extension_dir = "/usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20190902/"
912 extension=memcache.so
/etc/init.d/php-fpm reload
10.php -m |grep memcache # 查看是否加载成功
11. yum install memcached
12. cat /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS="" (如果OPTIONS="-l 127.0.0.1"即为监听本机的11211)
13. systemctl start memcached
14. yum install telnet -y
15. telnet localhost 11211
Trying ::1%1...
Connected to localhost.
Escape character is '^]'.
set name 0 6 3 (0编号 6缓存时间s 3限制字符数 )
zjy
STORED
get name (设置缓存name 过5秒再获取name)
VALUE name 0 3
zjy
END
delete name
NOT_FOUND
16. cd ~/lnmp/memcache-4.0.5.2
cp memcache.php example.php /usr/local/lnmp/nginx/html/
17. cd /usr/local/lnmp/nginx/html/
vim memcache.php
23 define('ADMIN_PASSWORD','westos'); // Admin Password
28 $MEMCACHE_SERVERS[] = '172.25.60.253:11211'; // add more as an array
29 #$MEMCACHE_SERVERS[] = 'mymemcache-server2:11211'; // add more as an array
测试:
[kiosk@foundation60 images]$ ab -c 10 -n 5000 http://172.25.60.253/index.php
Time taken for tests: 18.291 seconds
Complete requests: 5000
Failed requests: 466
[kiosk@foundation60 images]$ ab -c 10 -n 5000 http://172.25.60.253/example.php
Time taken for tests: 2.630 seconds
Complete requests: 5000
Failed requests: 0
速度和成功率明显提高