Mac 下 MAMP PRO 安装memcache扩展以及 memcache服务器端

因为其那边编译安装过redis 部分现在就不再重复编译PHP了 不了解的可以查看
Mac MAMP PRO 安装redis扩展以及 redis服务器端

首先要分清memcache服务端和客户端。服务端是memcached,客户端就是php的扩展了。

安装memcache扩展

1、安装autoconf brew install autoconf 可能有部分已经安装过

2、这边 memcached 扩展在这就用 pecl 直接安装了 首先进入相对应的PHP版本的 bin目录找到 pecl的所在 然后 直接执行 。sudo ./pecl install memcache 然后就会自动安装了

按照上图所说,在php.ini中最后加上 extension=memcache.so重启 MAMP,打开phpinfo() , 会看到 memcache 模块 ,到现在扩展已经安装好了。

安装memcache 本地服务器端

安装服务端还是直接使用 Homebrew 安装, brew install memcached 注意是memcached启动命令 memcached -d -m 10 -u root -l 127.0.0.1 -p 11211 256 -P /tmp/memcached.pid 这就好了,还是一样具体的项目优化就多少了自己研究下吧;

附测试小实例

    $mem = new Memcache;
    $is_add = $mem->addServer('localhost',11211);
    $mem->set('key2','吆不错哦', false, 60);
    $key2 = $mem->get('key2');
    echo $key2."<BR>";
    $mem->replace('key2','这是真的吗 ?',false,60);
    $key2 = $mem->get('key2');
    echo $key2;
    exit();

注意

问题 1

configure: error: memcache support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located

ERROR: `/private/tmp/pear/temp/memcache/configure --enable-memcache-session=yes' failed
这个问题引起是因为zlib在安装时没有正确被引入,解决的办法是使用brew进行zlib的安装

brew install zlib
安装后执行 ./pecl install memcache 时还会出现同样的问题,需要将zlib的头文件及库文件添加至系统默认的路径

ln -s /usr/local/Cellar/zlib/1.2.8/include/* /usr/local/include  
ln -s /usr/local/Cellar/zlib/1.2.8/lib/* /usr/local/lib  

非特殊说明,本博所有文章均为博主原创。

备注:相关侵权、举报、投诉及建议等,请联系站长

添加新评论

昵称
邮箱
网站