how to use Memcache with symfony
There is only one Memcached
software, and it's the one available at https://memcached.org/.
There are two well-known PHP
libraries for Memcached
, called memcache
(http://php.net/manual/en/book.memcache.php) and memcached
(http://php.net/manual/en/book.memcached.php), so this is probably where your confusion comes from.
To use Memcached
with Symfony 2 I suggest to use an external bundle by LeaseWeb which provides all the required documentation: https://github.com/LeaseWeb/LswMemcacheBundle.
Starting with Symfony 3.3 there will be a native Memcached
adapter: see http://symfony.com/blog/new-in-symfony-3-3-memcached-cache-adapter.
Related videos on Youtube
mrsharko
Updated on September 15, 2022Comments
-
mrsharko over 1 year
I using symfony 2 and I want to use Memcache with it but the problem is I can't find any explain for Memcache I just found for memcached so are they the same setup steps ? I added this lines to install Memcache on symfony?
config.yml
framework: session: handler_id: session.handler.memcached
for parameters.yml
parameters: memcached_host: 127.0.0.1 memcached_port: 11211 memcached_prefix: custom_key_ memcached_expire: 14400
services.yml
services: session.handler.memcached: class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler arguments: [ "@session.memcached", { prefix: '%memcached_prefix%', expiretime: '%memcached_expire%' } ] services: session.memcached: class: Memcached arguments: persistent_id: %memcached_prefix% calls: - [ addServer, [ %memcached_host%, %memcached_port% ]] services: session.memcached: class: Madisoft\AppBundle\Utils\MemcachedWrapper arguments: persistent_id: '%memcached_prefix%' calls: - [ addServer, [ '%memcached_host%', '%memcached_port%' ] ]
-
Ionel Lupu about 5 yearsWhat if I want to store something per session? You last example stores data that every user can get. What If I want to store data for each user (like what native sessions do)? What happens if the user doesn't send the PHPSESSID?