HUST OJ由於明天比賽人數較多,怕影響參賽者的刷新頁面速度,因此加個Memcache緩存。一開始yum安裝,由於php版本比較高。而默認的二進制版memcache是由低版本編譯的,因此就形成 Class ‘Memcache’not found的錯誤。php
# cd /usr/local/src
# wget https://github.com/websupport-sk/pecl-memcache/archive/php7.zip
# unzip php7.zip
# cd pecl-memcache-php7
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make && make install
在php.ini的最下面添加nginx
[memcache]
extension_dir = "/usr/local/php70/lib/php/extensions/no-debug-non-zts-20151012/"
extension = "memcache.so"
配置Memcached的步驟
首先安裝Libevent事件觸發管理器。git
# wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar vxf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure -prefix=/usr/local/libevent # ./configure
# make && make install
# yum install libevent-devel
編譯安裝Memcachegithub
wget http://memcached.org/files/memcached-1.4.25.tar.gz
tar vxf memcached-1.4.25.tar.gz
cd memcached-1.4.25
./configure -with-libevent=/usr/local/libevent # ./configure
# make && make install
啓動Memcacheweb
# /usr/local/bin/memcached -d -m 128 -l 127.0.0.1 -p 11211 -u root # (128爲內存, 11211爲端口,root爲用戶組)
驗證啓動:瀏覽器
ps aux|grep memcached
重啓php-fpm ,從新加載nginx緩存
# pkill php-fpm
# /usr/local/php/sbin/php-fpm
# /usr/local/src/nginx/sbin/nginx -s reload
瀏覽器訪問test.php,文件內容,檢測是否整合php服務器
<?php $mem = new memcache; $mem->connect('localhost', 11211); $mem->set('key', 'cbam_liangshu!'); $val = $mem->get('key'); echo $val; ?>
安裝完成,此時能夠經過telnet 鏈接memcache服務器並 經過stats命令查看Memcache的工做狀態。php7