php7安装memcache 和 memcached 扩展

时间:2022-03-19 22:50:19
php7安装memcache 和 memcached 扩展

php7安装memcache 和 memcached 扩展

标签(空格分隔): php


memcache和memcached区别

    memcache:http://pecl.php.net/package/memcache
memcached:http://pecl.php.net/package/memcached memcached 是高性能的分布式内存缓存服务器,而PHP memcache 和 memcached 都是 Memcached 服务器的 PHP 扩展。其中memcache 比 memcached 早出现,所以一些老的代码可能还在用 memcache 扩展。memcached 后来出现,并且大部分框架都支持。
memcache 是一个原生版本,完全是在 PHP 框架内开发的,支持 OO(面向对象) 和非 OO 两套接口并存,而 memcached 是建立在 libmemcached 的基础上的,只支持 OO 接口。这就意味着在安装 memcache 扩展的时候不要求安装其他的东西,但是在安装 memcached 的时候会要求你安装 libmemcached。别嫌麻烦!因为 libmemcached 是 memcache 的 C 客户端,它具有低内存,线程安全等优点。据说新浪微博之前就全面将 PHP 的 memcache 替换成 PHP 的 memcached,在高并发下,稳定性果断提高。
比较尴尬的一点是 memcached 和 memcache 对应的服务端名字都是 memcached,大家使用 ps aux | grep memcache 就会发现守护进程的名字是 memcached(我的环境是 ubuntu16 LTS),其实后面的 d 可以理解为守护进程,因此网上有的人说 memcache 是客户端, memcached 是服务端就是这个意思,所以不要将客户端的 memcached 和服务端的 memcached 混淆了就好。

安装memcached扩展

    1 选择对应的tar包安装
https://pecl.php.net/package/memcached tar -zxvf memcached-3.0.4.tgz memcached-3.0.4 [phpize 和 php-config 要看自己的位置] /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make && make install Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
2 可能会出现的错误
![](https://img2018.cnblogs.com/blog/1458583/201811/1458583-20181122163300682-1894778112.png) 需要安装依赖 yum -y install libmemcached libmemcached-devel

安装memcache扩展

1 https://pecl.php.net/package/memcache
这个方式安装会失败: 貌似原因也是还不支持在 PHP7 下安装 memcache 扩展

php7安装memcache 和 memcached 扩展

2 github搜索 并且代码已经支持到 PHP7
git clone https://github.com/websupport-sk/pecl-memcache memcache 用 phpize 安装,步骤和 memcached 一样 cd memcache/ [phpize 和 php-config 要看自己的位置] /usr/local/php/bin/phpize ./configure --with-php-config=/usr/local/php/bin/php-config make && make install Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/

修改php.ini

vim /usr/local/php/etc/php.ini

在文件最后添加

php7安装memcache 和 memcached 扩展

重启: service php-pfm restart | service httpd restart
如果报错:
添加.so的路径 把 extension_dir ./ 改成 /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/

php7安装memcache 和 memcached 扩展

php7安装memcache 和 memcached 扩展

再次重启

如果还不行 再次安装 多试几次!

php7安装memcache 和 memcached 扩展