PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 12, 2022

[FIXED] how to inject "memcache" to service.yml?

 November 12, 2022     memcached, php, session, session-cookies, symfony     No comments   

Issue

I installed memcache lib and added it to

framework:  
    session:
        handler_id: session.handler.memcache

but when I trying to use it I get this error

  [Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]  
  You have requested a non-existent service "session.handler.memcache".       

Solution

You want to use memcache or memcached? These are two different extensions, so be aware of that. And I suggest to use memcached, memcache is dead.

Serivce session.handler.memcache is not defined, so you have to define one implementing SessionHandlerInterface, in your case MemcacheSessionHandler.

First, we need to define memcache instance as a service, so we can pass it to MemcacheSessionHandler constructor:

memcache:
    class: \Memcache
calls:
    - [ addServer, [ %host_parameter%, %port_parameter% ]]

Then, your session handler:

session.handler.memcache:
        class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler
        arguments: [@memcache]

You can also use a bundle like cache/adapter-bundle to register a PSR-6 compatible service (or even a symfony cache component, introduced in 3.1) and use Psr6SessionHandler.

If you want to use memcached, it's almost the same configuration-wise.



Answered By - Mateusz Sip
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing