(转载:) 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!
相关推荐
商业编程-源码-access源代码 storing_paintbrush_in_accessdb.zip
商业编程-源码-access源代码_storing_paintbrush_in_accessdb_update.zip
access源代码:storing_paintbrush_in_accessdb 关键字:storing_paintbrush_in_accessdb,access
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, Second Edition is a comprehensive introduction to computing, storing, and networking in the AWS cloud. Readers will find clear, relevant coverage of all the essential ...
access源代码:storing_paintbrush_in_accessdb_update 关键字:storing_paintbrush_in_accessdb_update,access
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 ...
了解如何在 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 - ...
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 ...
Chapter 2 The Stack Chapter 3 Example - Bare Bones Environment Chapter 4 Example - Web Environment Chapter 5 Example - Beanstalk Environment Chapter 6 Security Chapter 7 Building Images Chapter 8 ...
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 ...
5 Storing and retrieving data 5.1 Using preferences 5.2 Using the filesystem 5.3 Persisting data to a database 5.4 Working with ContentProvider classes 5.5 Summary 6 Networking and web services 6.1 An...
├─dataset storing the corpped images │ └─Vladimir_Putin ├─examples show examples ├─facebank storing the raw/origin images │ └─Vladimir_Putin ├─models storing the pretrained models ├─...
Cloud Storage Cloud Storage
USB4 1.0 ECN - Storing Credit and TMU Packets.pdf