时间:2021-07-01 10:21:17 帮助过:53人阅读
wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gzwget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gzwget http://pecl.php.com/get/memcache-2.2.5.tgztar zxvf libevent-1.4.13-stable.tar.gztar zxvf memcached-1.4.4.
wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz wget http://memcached.googlecode.com/files/memcached-1.4.4.tar.gz wget http://pecl.php.com/get/memcache-2.2.5.tgz tar zxvf libevent-1.4.13-stable.tar.gz tar zxvf memcached-1.4.4.tar.gz cd libevent-1.4.13-stable ./configure --prefix=/usr make make install ln -s /usr/lib/libevent-1.4.so.2 /usr/lib64/libevent-1.4.so.2 cd memcached-1.4.4 ./configure --prefix=/home/memcached --enable-64bit make make install /home/memcached/bin/memcached -d -m 1024 -p 11211 -u root
参数说明:
-d 启动为守护进程
-m
cd memcache-2.2.5 /home/php/bin/phpize ./configure --prefix=/home/phpmemcache --with-php-config=/home/php/bin/php-config make make install sed –i ‘s:./:/home/php/lib/php/extensions/no-debug-zts-20060613/:g’ /home/php/lib/php.ini sed –i ‘/zip.dll/aextension=memcache.so’ /home/php/lib/php.ini cat >> /cache/data/test.php addServer('127.0.0.1', 11211); $memcache->addServer('192.168.0.2', 11212); $version = $memcache->getVersion(); echo "Server's version: ".$version."n"; $tmp_object = new stdClass; $tmp_object->str_attr = 'test'; $tmp_object->int_attr = 123; $memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server"); echo "Store data in the cache (data will expire in 10 seconds)n"; $get_result = $memcache->get('key'); echo "Data from the cache:n"; var_dump($get_result); ?> EOF
curl http://localhost/test.ph Server's version: 1.4.4 Store data in the cache (data will expire in 10 seconds) Data from the cache: object(stdClass)#3 (2) { ["str_attr"]=> string(4) "test" ["int_attr"]=> int(123) } # telnet localhost 11211
Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. stats STAT pid 3015 STAT uptime 3185???????????????????????????????? memcached运行的秒数 STAT time 1267090234 STAT version 1.4.4 STAT pointer_size 64 STAT rusage_user 0.000000 STAT rusage_system 0.000000 STAT curr_connections 10 STAT total_connections 18 STAT connection_structures 11 STAT cmd_get 3?????????????????????????????????? 查询缓存的次数 STAT cmd_set 5???????????????????????????????????设置key=>value的次数 STAT cmd_flush 0 STAT get_hits 3??????????????????????????????????? 缓存命中的次数 STAT get_misses 0 STAT delete_misses 0 STAT delete_hits 0 STAT incr_misses 0 STAT incr_hits 0 STAT decr_misses 0 STAT decr_hits 0 STAT cas_misses 0 STAT cas_hits 0 STAT cas_badval 0 STAT auth_cmds 0 STAT auth_errors 0 STAT bytes_read 2697 STAT bytes_written 1150 STAT limit_maxbytes 1073741824 STAT accepting_conns 1 STAT listen_disabled_num 0 STAT threads 4 STAT conn_yields 0 STAT bytes 1255 STAT curr_items 2 STAT total_items 5 STAT evictions 0 END
完成~~~以上仅为试验,如果只是一个小web单机环境的话,只需要php+eaccelerator(或者apc/xcache等)就足够了。用php+memcached+mysql-proxy+mysql是大型网站架构的事情~~
原文地址:memcached部署, 感谢原作者分享。