(转载:) http://blog.kevingomez.fr/2012/12/18/storing-symfony2-sessions-in-memcached/
Storing Symfony2 sessions in memcached
- 18 décembre 2012 /
- Kévin G. /
- Dev', WebDev' /
- 2s commentaires
Even if the only example in Symfony cookbook is about storing sessions with PDO, adapting it to memcached is pretty straightforward.
Memcached installation
If it’s not already done, install the following packages (supposing you are on a Debian-like system) :
1 |
aptitude install memcached php5-memcached
|
This will install a memcached server and the PHP extension to use it. The server should e running on localhost, port 11211.
Just to be sure, check that the php extension has been enabled.
Modifying the session handler
Now, we’ll update our configuration to make our app use memcache to store sessions. To do that, we’ll use the MemcachedSessionHandler provided in the HttpFoundation bundle. As he need a \Memcached instance to work (and chat with our memcached server), we’ll use services to build the whole thing.
1234567891011 |
services:
session.memcached:
class: Memcached
arguments:
persistent_id: %session_memcached_prefix%
calls:
- [ addServer, [ %session_memcached_host%, %session_memcached_port% ]]
session.handler.memcached:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler
arguments: [@session.memcached, { prefix: %session_memcached_prefix%, expiretime: %session_memcached_expire% }]
|
As usual, the configuration variables are stored in the parameters.yml file. Considering how simple they are, I won’t explain them but don’t hesitate to read memcached’s documentation if they are not clear enough.
1234567 |
parameters:
# ...
session_memcached_host: localhost
session_memcached_port: 11211
session_memcached_prefix: sess
session_memcached_expire: 3600
|
Once we are done configuring our services, we just have to tell our application to use the service we just created.
123456789 |
imports:
# ....
- { resource: services/session.yml }
framework:
# ....
session:
handler_id: session.handler.memcached
|
That’s it!
相关推荐
这个名为"storing_paintbrush_in_accessdb"的项目似乎是一个利用Access进行数据存储的具体应用,可能是为了管理画笔(paintbrush)相关的产品信息或者业务流程。下面将详细解析这个压缩包中的潜在知识点: 1. **...
2. 数据库设计:在“storing_paintbrush_in_accessdb”项目中,可能涉及创建一个或多个表来存储画笔的相关信息,如画笔类型、颜色、尺寸、库存量、供应商信息等。合理的设计是确保数据完整性和一致性的关键,这通常...
Sample Application to Prepare HLv2 Messages for Storing in MySQL
Swift library for making storing data in a SQLite database easy as pie.zip,Swift library for making storing data in a SQLite database simple and magic-free
Amazon Web Services in Action introduces you to computing, storing, and networking in the AWS cloud. You'll start with a broad overview of AWS and learn how to spin-up servers manually and from the ...
"accessVC源代码:storing_paintbrush_in_accessdb" 这个标题表明我们关注的是一个使用Visual C++(VC)或MFC(Microsoft Foundation Classes)开发的项目,该项目涉及到将画笔工具(paintbrush)的数据存储在Access...
标题中的"accessVC源代码:storing_paintbrush_in_accessdb_update"表明这是一个关于使用Visual C++(VC)和Microsoft Foundation Classes (MFC) 框架来操作Access数据库的源代码示例。这个示例可能涉及到将画笔...
了解如何在 Matlab 中创建和存储符号变量。 我们将使用符号变量进行代数、微积分等计算。
Chapter 11 - Storing Binary Data in MySQL Chapter 12 - Cookies and Sessions in PHP Appendix A - MySQL Syntax Appendix B - MySQL Functions Appendix C - MySQL Column Types Appendix D - ...
#### Chapter 2: Storing Sessions in a Traditional Database ##### The Main Problem with This Approach Storing session data in a traditional database presents several challenges: - **Performance ...
在《Yoshida_Hiroshi_Experiments_in_Storing_Data__Cold_Storage_Services.pdf》这份文档中,作者Hiroshi Yoshida对科学数据在云冷存储服务中的存储进行了详细的探讨与实验分析。该文档主要介绍了云冷存储的概念、...
You want to share Spark RDD directly in-memory (without storing the state into the disk), which can dramatically increase the performance of the Spark jobs. You are planning to migrate to ...
27.3 Storing State in C Functions 251 28 User-Dened Types in C 259 28.1 Userdata 260 28.2 Metatables 262 28.3 Object-Oriented Access 265 28.4 Array Access 267 28.5 Light Userdata 268 29 ...
using py2neo storing picture in neo4j in binary code creating nodes merge_one
Amazon Web Services in Action, Second Edition is a comprehensive introduction to computing, storing, and networking in the AWS cloud. You’ll find clear, relevant coverage of all the essential AWS ...
├─dataset storing the corpped images │ └─Vladimir_Putin ├─examples show examples ├─facebank storing the raw/origin images │ └─Vladimir_Putin ├─models storing the pretrained models ├─...
Chapter 5 - Storing and Retrieving Data in Memory Chapter 6 - Applying Conditional Logic Chapter 7 - Processing Lots of Data with Loops Chapter 8 - Enhancing Code Structure ...