您的位置:首页 > 数据库 > Memcache

PHP 连接 Memcached 服务

2015-11-09 14:55 507 查看
PHP Memcache 扩展包下载地址:http://pecl.php.net/package/memcache,你可以下载最新稳定包(stable)

wget http://pecl.php.net/get/memcache-2.2.7.tgz tar -zxvf memcache-2.2.7.tgz
cd memcache-2.2.7
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

修改/etc/php.ini,加入extension = memcache.so

重启apache

php -m检查是否安装成功

php-memcached安装:http://www.cnblogs.com/yangxia-test/p/4195288.html

PHP 连接 Memcached

<?php
  $memcache = new Memcache;             //创建一个memcache对象
  $memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器
  $memcache->set('key', 'test');        //设置一个变量到内存中,名称是key 值是test
  $get_value = $memcache->get('key');   //从内存中取出key的值
  echo $get_value;
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: