Storing Magento sessions in memcached via socket
来源:互联网 发布:excel防止数据粘贴 编辑:程序博客网 时间:2024/05/19 21:41
Installing memcached on your server
To use memcached in Magento, you will first need to install it on your server. As root you can use your package manager to install memcached. With CentOS Linux this will look like this:
yum install memcached php-pecl-memcached
After installing the packages, the service needs to be started up. We also use chkconfig to start the service automatically after reboots:
service memcached start
chkconfig memcached on
Now the memcached service is ready for use.
Configuring Magento for storing sessions in memcache
Next, the Magento application needs to be told to save sessions in the memcached database. To do this, we open up the Magento file app/etc/local.xml and locate the line mentioning <session_save>. When sessions are currently save in the database, it might look like this:
<session_save><![CDATA[database]]></session_save>
Replace this line with the following lines:
<session_save><![CDATA[memcache]]></session_save>
<session_save_path>
<![CDATA[tcp://127.0.0.1:11211?persistent=1&weight=2&timeout=10&retry_interval=10]]>
</session_save_path>
Afterwards, flush the Magento cache. Now, sessions should be saved into the memcached database. If you want to, you can check out the memcached-tool to see statistics on how the memcached database is behaving:
memcached-tool 127.0.0.1:11211 display
memcached-tool 127.0.0.1:11211 stats
Reconfiguring memcached to run over a UNIX socket
Now, memcached by default is setup for networking and is listening to the TCP-port 11211. This is useful when you have multiple servers, where for instance a Magento webserver is connecting to a different server for the database. The memcached database can then be accessed remotely via the network. But if you have only a single server, running Magento, MySQL and everything, then using memcached through TCP/IP is actually a (very small) waste of resources. Instead of using TCP/IP, you can also use UNIX sockets to skip networking and still use memcached.
To do this, memcached needs to reconfigured to listen to a UNIX-socket instead. Open up the file /etc/sysconfig/memcached and locate the following line:
OPTIONS=""
Replace it with this line:
OPTIONS="-s /var/tmp/memcache.socket -a 0777"
This instructs memcached to bind itself not to a TCP/IP socket but a file socket /var/tmp/memcache.socket instead. Because the memcached service is being ran as UNIX-user memcached, the socket will also be owned by this user. To allow other UNIX-users like the webserver-user to read and write to memcached, we set the permissions to 777. If your servers is setup as shared hosting server, you will definitely need to look into the security aspects of this.
Restart the memcached service, so the changes take effect:
service memcached restart
You can verify now whether memcached is being used by using the memcached-tool command as follows:
memcached-tool /var/tmp/memcache.socket display
Reconfiguring Magento to talk to memcached via the UNIX socket
Next, we go back to the Magento app/etc/local.xml to reconfigure it so that Magento will access memcached via UNIX-socket and not TCP/IP. Locate the previous lines again and replace them with the following:
<session_save><![CDATA[memcache]]></session_save>
<session_save_path>
<![CDATA[unix:///var/tmp/memcache.socket?persistent=1&weight=2&timeout=10&retry_interval=10]]>
</session_save_path>
Again flush the Magento cache. If all goes well, memcached should still be usable and now accessible through the UNIX-socket instead.
- Storing Magento sessions in memcached via socket
- Add Product Images via CSV in Magento
- Storing data in browser
- Storing nested objects in Redis
- Remote Connection via Proxy Server in TCP/IP Socket
- Storing XML in Relational Databases (1)
- Storing XML in Relational Databases(2)
- Storing Java objects in MySQL blobs
- Securely storing your secrets in R code
- Storing XML in Relational Databases (1)
- Magento中使用MemCached
- magento 结合 memcached
- nginx+tomcat+memcached实现sessions共享
- Saving PHP Sessions in Redis
- Storing Information: Variables and Constants in C (一)
- Storing Information: Variables and Constants in C (二)
- Storing Information: Variables and Constants in C (三)
- Storing Additional User Information in membership db - ASP.NET
- 文件误删后,ubuntu系统重新安装pycharm.
- 【学习ARToolkit小记之三】 摄像头标定(Camera Calibration)
- ASP.NET MVC 4实现局部刷新
- loaded the "BlueView" nib but the view outlet was not set 错误的解决办法
- 【Unity】GPU优化
- Storing Magento sessions in memcached via socket
- asp.net系统中根据经纬度坐标,直接调用google地图,显示位置
- vs2010 注释与取消注释
- 黑马程序员——Java基础视频笔记(一)
- MFC控件添加变量时,control和value的区别
- Xilinx ISE Design Suite 14.7 ISim 简单仿真
- ALV最后一行写合计
- 创业型公司,你要不要去?
- 使用 Spring Data JPA 简化 JPA 开发