1.认识memcache,要将它与mysql联系起来,不同的是它不会保存数据,重启后数据就没了。
2.php中使用,需要有php55-memcached或php55-memcache扩展,通过该扩展调用主机中的memcache服务器,安装memcache服务器:
brew install memcache
3.mac中将memcached设为开机启动,输入:
brew info memcached
该命令会提示设置开机启动的命令,如下:
brew info memcached
memcached: stable 1.4.20
http://memcached.org/
Conflicts with: mysql-cluster
/usr/local/Cellar/memcached/1.4.20 (10 files, 184K) *
Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/memcached.rb
==> Dependencies
Required: libevent ✔
==> Options
--enable-sasl
<span style="white-space:pre"> </span>Enable SASL support -- disables ASCII protocol!
--enable-sasl-pwdb
<span style="white-space:pre"> </span>Enable SASL with memcached's own plain text password db support -- disables ASCII protocol!
==> Caveats
To have launchd start memcached at login:
ln -sfv /usr/local/opt/memcached/*.plist ~/Library/LaunchAgents
Then to load memcached now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
Or, if you don't want/need launchctl, you can just run:
/usr/local/opt/memcached/bin/memcached
复制命令:
ln -sfv /usr/local/opt/memcached/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
这样开机启动就设置好了。
4.出现问题首先检查phpinfo()中是否有该扩展,该扩展的状态是否可用。然后注意扩展信息的配置,也就是链接memcache语句,以yii2为例,语句为:
'components' => [
'cache' => [
'class' => 'yii\caching\MemCache',
'servers' => [
[
'host' => '127.0.0.1',
'port' => 11211,
'weight' => 60,
],
],
],
],
问题1:Memcache::set(): Server 127.0.0.1 (tcp 11211) failed with: Connection refused (61)。
检查memcache是否开启,“memcached -d ” 或者“telnet localhost 11211”
问题2:Memcache::set(): php_network_getaddresses: getaddrinfo failed: nodename nor
检查服务器的地址配置是否有问题。