Giter VIP home page Giter VIP logo

lswmemcachebundle's Introduction

Deprecated

This repository is no longer being actively maintained. We encourage you to not use this code. If you rely on this code you might want to fork the repository to keep your systems from breaking, if we remove this repository in the future.

Build Status Average time to resolve an issue Percentage of issues still open Total Downloads

LswMemcacheBundle

screenshot

If you want to optimize your web application for high load and/or low load times Memcache is an indispensable tool. It will manage your session data without doing disk I/O on web or database servers. You can also run it as a central object storage for your website. In this role it is used for caching database queries using the Doctrine caching support or expensive API calls by implementing the caching using Memcache "get" and "set" commands.

This Symfony bundle will provide Memcache integration into Symfony and Doctrine for session storage and caching. It has full Web Debug Toolbar integration that allows you to analyze and debug the cache behavior and performance.

Read the LeaseWebLabs blog about LswMemcacheBundle

Requirements

  • PHP 5.3.10 or higher
  • php-memcache 3.0.6 or higher
  • memcached 1.4 or higher

NB: This bundle no longer uses the PHP "memcached" extension that uses "libmemcached", see "Considerations".

PHP7 support is currently (experimentally) available by compiling and installing: https://github.com/websupport-sk/pecl-memcache/tree/php7

Installation

To install LswMemcacheBundle with Composer just add the following to your 'composer.json' file:

{
    require: {
        "leaseweb/memcache-bundle": "*",
        ...
    }
}

The next thing you should do is install the bundle by executing the following command:

php composer.phar update leaseweb/memcache-bundle

Finally, add the bundle to the registerBundles function of the AppKernel class in the 'app/AppKernel.php' file:

public function registerBundles()
{
    $bundles = array(
        ...
        new Lsw\MemcacheBundle\LswMemcacheBundle(),
        ...
    );

Configure the bundle by adding the following to app/config/config.yml':

lsw_memcache:
    session:
        pool: default
    pools:
        default:
            servers:
              - { host: localhost, tcp_port: 11211 }

Install the following dependencies (in Debian based systems using 'apt'):

apt-get install memcached php5-memcache

Do not forget to restart you web server after adding the Memcache module. Now the Memcache information should show up with a little double arrow (fast-forward) icon in your debug toolbar.

Usage

When you want to use the cache from the controller you can simply call:

$this->get('memcache.default')->set('someKey', 'someValue', 0, $timeToLive);
$this->get('memcache.default')->get('someKey');

The above example shows how to store value 'someValue' under key 'someKey' for a maximum of $timeToLive seconds (the 0 parameter are the 'flags'). In the second line the value is retrieved from Memcache. If the key can not be found or the specified number of seconds have passed the 'get' function returns the value 'false'.

Configuration

Below you can see an example configuration for this bundle.

lsw_memcache:
    pools:
        default:
            servers:
                - { host: 10.0.0.1, tcp_port: 11211, weight: 15 }
                - { host: 10.0.0.2, tcp_port: 11211, weight: 30 }
            options:
		        allow_failover: true
		        max_failover_attempts: 20
		        default_port: 11211
		        chunk_size: 32768
		        protocol: ascii
		        hash_strategy: consistent
		        hash_function: crc32
		        redundancy: true
		        session_redundancy: 2
		        compress_threshold: 20000
		        lock_timeout: 15
        sessions:
            servers:
                - { host: localhost, tcp_port: 11212 }

Session Support

This bundle also provides support for storing session data on Memcache servers. To enable session support you will have to enable it through the session key (auto_load is true by default). Note that the only required subkey of the session support is pool (a valid pool). You can also specify a key prefix and a ttl.

lsw_memcache:
    session:
        pool: sessions
        auto_load: true
        prefix: "session_"
        ttl: 7200
        locking: true
        spin_lock_wait: 150000
    # pools

Note that the session locking is enabled by default and the default spin lock is set to poll every 150 milliseconds (150000 microseconds).

Session Management for applications running behind a load balancer

When your application is running on multiple servers you have to be aware that all your instances should be comunicating with 1 Caching server for consistency; otherwise each instance would have its own session and this would produce unexpected results.

In order for you to avoid the problem described above you have to add LockingSessionHandler as service. By doing this, all your instances will use the session handler and the session handler would store the data in the configured memcache server.

my.memcache.service:
    class: Memcache
    calls:
        - [addServer, ['your_memcache_address', 'your_memcache_port']] 

my.memcached.session.handler:
    class: Lsw\MemcacheBundle\Session\Storage\LockingSessionHandler
   arguments:
       - "@my.memcache.service"
       - prefix: 'your_prefix'
       - expiretime: 'your_expire_time'

Doctrine Support

This bundle also provides support for Doctrine caching on Memcache servers. To enable Doctrine caching you will have to enable it through the doctrine key. Note that you can specify all three kinds of Doctrine caching: 'metadata', 'result' and 'query'. The required keys within those subkeys are both pool (a valid pool) and entity_manager (normally: default). You can also specify a prefix.

lsw_memcache:
    doctrine:
        metadata_cache:
            pool: default
            entity_manager: default          # the name of your entity_manager connection
            document_manager: default        # the name of your document_manager connection
        result_cache:
            pool: default
            entity_manager: [default, read]  # you may specify multiple entity_managers
            prefix: "result_"                # you may specify a prefix for the entries
        query_cache:
            pool: default
            entity_manager: default
    # pools

Firewall Support

This bundle also provides support a firewall that limits the number of concurrent requests per IP address. It maintains a counter of running requests per IP address and delays (throttles) the requests if nessecary. To enable firewall support you will have to enable it through the firewall key. Note that the only required subkey of the firewall support is pool (a valid pool). You can also specify a key prefix and a concurrency (default is 10). If you use one or more reverse proxies, then specify them in the reverse_proxies key.

lsw_memcache:
    firewall:
        pool: firewall
        prefix: "firewall_"
        concurrency: 10
        reverse_proxies: [10.0.0.1]
    # pools

ADP: Anti Dog Pile

Let us examine a high traffic website case and see how Memcache behaves:

Your cache is stored for 90 minutes. It takes about 3 second to calculate the cache value and 1 ms second to read the cached value from the cache. You have about 5000 requests per second and let's assume that the value is cached. You get 5000 requests per second taking about 5000 ms to read the values from cache. You might think that that is not possible since 5000 > 1000, but that depends on the number of worker processes on your web server. Let's say it is about 100 workers (under high load) with 75 threads each. Your web requests take about 20 ms each. Whenever the cache invalidates (after 90 minutes), during 3 seconds, there will be 15000 requests getting a cache miss. All the threads getting a miss will start to calculate the cache value (because they don't know the other threads are doing the same). This means that during (almost) 3 seconds the server wont answer a single request, but the requests keep coming in. Since each worker has 75 threads (holding 100 x 75 connections), the amount of workers has to go up to be able to process them.

The heavy forking will cause extra CPU usage and the each worker will use extra RAM. This unexpected increase in RAM and CPU is called the 'dog pile' effect or 'stampeding herd' or 'thundering herd' and is very unwelcome during peak hours on a web service.

There is a solution: we serve the old cache entries while calculating the new value and by using an atomic read and write operation we can make sure only one thread will receive a cache miss when the content is invalidated. The algorithm is implemented in AntiDogPileMemcache class in LswMemcacheBundle. It provides the getAdp(), setAdp() and deleteAdp() functions that can be used as replacements for the normal get, set and delete.

Please note:

  • ADP might not be needed if you have low amount of hits or when calculating the new value goes relatively fast.
  • ADP might not be needed if you can break up the big calculation into smaller, maybe even with different timeouts for each part.
  • ADP might get you older data than the invalidation that is specified. Especially when a thread/worker gets "false" for "get" request, but fails to "set" the new calculated value afterwards.
  • ADP's "getAdp", "setAdp" and "deleteAdp" are more expensive than the normal "get", "set" and "delete", slowing down all cache hits.
  • ADP does not guarantee that the dog pile will not occur. Restarting Memcache, flushing data or not enough RAM will also get keys evicted and you will run into the problem anyway.

Considerations

LswMemcacheBundle uses the 'memcache' PHP extension (memcached client) and not the libmemcache based 'memcached' PHP extension.

Major version 1 of this bundle used the other extension. In major version 2 of this bundle the full featured version 3.0.8 of PECL "memcache" (without the 'd') was chosen, due to it's complete feature set and good design and support.

Known issues

The session write that invokes a memcache set operation is executed after the page has been rendered. The collect call of the memcache data collector is executed before the rendering of the page is complete and therefor also before the session write is executed. This causes the session writes not to show up in the Web Debug Toolbar.

Credits

Doctrine support is based on the implementation in SncRedisBundle:

https://github.com/snc/SncRedisBundle by Henrik Westphal

  • DependencyInjection/LswMemcacheExtension.php
  • DependencyInjection/Configuration.php
  • DependencyInjection/Compiler/EnableSessionSupport.php

Are based on implementation in:

https://github.com/Emagister/MemcachedBundle by Christian Soronellas

  • Command/StatisticsCommand.php

Is based on an implementation in:

https://github.com/beryllium/CacheBundle by Kevin Boyd

License

This bundle is under the MIT license.

lswmemcachebundle's People

Contributors

arthurhall avatar d3f3kt avatar dbu avatar dhanielo avatar falvarez avatar gabrielanca avatar gfyrag avatar gmansilla avatar h4cc avatar jasperstafleu avatar jbaginski avatar jimaek avatar lancergr avatar mauriau avatar mevdschee avatar nrocco avatar onewheelskyward avatar spoelwijk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lswmemcachebundle's Issues

install bundle dependency error

I get the following error when I try to install the bundle:

Problem 1
- Installation request for symfony/framework-standard-edition 2.3.x-dev -> satisfiable by symfony/framework-standard-edition[2.3.x-dev].
- symfony/framework-standard-edition 2.3.x-dev requires leaseweb/memcache-bundle * -> no matching package found.

Potential causes:

I have symfony 2.3.3 installed.

Runtime Notice: Declaration of LoggingMemcache::get() should be compatible with Memcached::get

Full notice:

Runtime Notice: Declaration of Lsw\MemcacheBundle\Cache\LoggingMemcache::get() should be compatible with Memcached::get($key, $cache_cb = NULL, &$cas_token = NULL, &$udf_flags = NULL)

I'm using Memcached version 2.2.0

I can't quite get my head around this one as it looks fine to me
https://github.com/php-memcached-dev/php-memcached/blob/master/memcached-api.php#L192

Looks identical to me as https://github.com/LeaseWeb/LswMemcacheBundle/blob/master/Cache/LoggingMemcache.php#L1380

Am I missing something here (sorry its been a long week)?

Sessions doesn't work with the bundle & SF2.2.1

Hi,

I'm on Symfony 2.2.1& LswMemcacheBundle is installed. I've tried to run sessions handling on two different servers, but after ie. login, nothing happend – session isn't writed down. If I switch back to file-based-sessions everything seems to work.

My config.yml:

lsw_memcache:
    session:
        client: sessions
        prefix: "my_session_"
        ttl: 7200
    clients:
        default:
            hosts:
              - { dsn: localhost, port: 11211 }
            options:
                prefix_key: "my-dev"
        sessions:
            hosts:
                - { dsn: localhost, port: 11212 }

Different Memcache Servers on different environments

Hello,

I am having a problem with your Bundle. When executing my functional tests, i have an environment "test" which includes config_test.yml. That contains:

lsw_memcache:
    pools:
        default:
            servers:
                - { host: localhost, tcp_port: 11211, weight: 100 }
                - { host: localhost, tcp_port: 11211, weight: 50 }

It works totally fine on my local dev machine. What i now need is a different configuration for my CI-Server. The CI-Server has another memcache host and port. But how can i change parameters for local test execution and CI-Server test execution? The thing is, both uses the environment "test".

Problem with new webprofiler

The profiler template "LswMemcacheBundle:Collector:memcache.html.twig" for data collector "memcache" does not exist.
I have symfony version 3.0.3

HHVM compatibility

Hi there,

the current version of this Bundle 1.2.13 is not useable with HHVM in stable version 3.2.0.

The problem is, that the memcached extension is using the version string 2.2.0b1 instead of just 2.2.0.
Is there a way to make this work? Maybe we could integrate tests running on travis against hhvm and hhvm-nightly to support them.

Version output:

# hhvm --version
HipHop VM 3.2.0 (rel)
Compiler: tags/HHVM-3.2.0-0-g01228273b8cf709aacbd3df1c51b1e690ecebac8
Repo schema: c52ba40f4a246d35a88f1dfc1daf959851ced8aa
# hhvm memcached_version.php 
string(7) "2.2.0b1"

InvalidArgumentException: The following arguments are not supported: ttl

I'm receiving an exception when trying to clear the cache/access my site with the bundle installed. Symfony version is 2.1.7, and the exception happens in vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MemcachedSessionHandler.php line 58.

I would post a stacktrace, but refers to my cached appDevDebugProjectContainer file, which is I believe no use to you.

Segfaults with v1.2.15

Using the v1.2.15 release this PHP version will cause a silent segfault:

PHP 5.3.10-1ubuntu3.14 with Suhosin-Patch (cli) (built: Sep  4 2014 07:08:49) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

Have not yet been abled to trace down the cause, but will update when i find it.

deleteByRegex() support

In the doctrine documentation (http://docs.doctrine-project.org/en/2.0.x/reference/caching.html#by-regular-expression) it states:

In order to use deleteByRegex(), deleteByPrefix(), deleteBySuffix(), deleteAll(), count() or getIds() you must enable an option for the cache driver to manage your cache IDs internally. This is necessary because APC, Memcache, etc. don’t have any advanced functionality for fetching and deleting. We add some functionality on top of the cache drivers to maintain an index of all the IDs stored in the cache driver so that we can allow more granular deleting operations.

<?php
$cacheDriver->setManageCacheIds(true);

Is there any way to activate this with the LswMemcacheBundle? I am using memcached and I would like to use the deleteByRegex() function. Or be able to use delete() with a wildcard in it.

Warning: Parameter 3 to Memcached::get() expected to be a reference

Since 1.2.7, where the call was changed (https://github.com/LeaseWeb/LswMemcacheBundle/blob/v1.2.6/Cache/LoggingMemcache.php#L77) I'm getting: ContextErrorException: Warning: Parameter 3 to Memcached::get() expected to be a reference, value given in /vagrant/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php line 35.

The change is here (https://github.com/LeaseWeb/LswMemcacheBundle/blob/v1.2.7/Cache/LoggingMemcache.php#L31). By calling the forward_static_call_array('parent::get', func_get_args()) the reference is lost?

I guess all the functions using reference are affected?

Maybe this being just a warning is not important, but it throws error in our Symfony project.

enable memcached extensions

Hi guys,

I would like store my datas on a remote server.
Do I have to install memcache on all my webservers ? composers says so ... :(

PHP Strict Standards errors

Hi,

When I upload my website folder on my server, I got this error for almost every function of LswMemcacheBundle:

PHP Strict Standards: Declaration of Lsw\MemcacheBundle\Cache\LoggingMemcache::replace() should be compatible with Memcached::replace($key, $value, $expiration = NULL, $udf_flags = NULL) in XXX/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php on line 501

I don't want to disable logs for debugging purpose.
I use php 5.5.11 and memcached 1.4.13

Thank you :-)

Warning: MemcachePool::set(): The lowest two bytes of the flags array is reserved for pecl/memcache internal use

Hello,

i'm running a server on ubuntu 14.04, with the 3.0.8 memcache extension and i get this :

An exception has been thrown during the rendering of a template ("Warning: MemcachePool::set(): The lowest two bytes of the flags array is reserved for pecl/memcache internal use")

The only trail i found was here :
http://stackoverflow.com/questions/3740317/php-memcached-error

but i didn't find a way to solve that at the moment.

Thanks in advance for any help you could provide.

Add memcache class as parameter

Hello,

First of all, thank you for building a very nice cache bundle.

I wouldd like to load my own class extended from Lsw\MemcacheBundle\Cache\AntiDogPileMemcache in stead of this class.

Is there any way to new the definition with a parameter like memcache.cache.class to use my own class ?
$memcache = new Definition('Lsw\MemcacheBundle\Cache\AntiDogPileMemcache');

Thank you

'LoggingMemcache::getMulti() should be compatible with Memcached::getMulti'

Hi there,

i am using this version of your Bundle:

        "name": "leaseweb/memcache-bundle",
        "version": "v1.2.13",
        "version_normalized": "1.2.13.0",

and get this error:

PHP Strict standards:  Declaration of Lsw\\MemcacheBundle\\Cache\\LoggingMemcache::getMulti() should be compatible with Memcached::getMulti(array $keys, &$cas_tokens = NULL, $flags = NULL, &$udf_flags = NULL) in .../vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php on line 1364

My System:

# cat /etc/debian_version 
7.5
# php --version
PHP 5.5.13-1~dotdeb.1 (cli) (built: Jun  6 2014 18:05:23) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
# php memcached_version.php 
string(5) "2.2.0"

I have seen these kind of errors have occured a few times now. Hope my description helps.
If you have a branch with a fix, i can try it before tagging.

Setting prefix_key causes ErrorException

I have the following config:

lsw_memcache:
    clients:
        general:
            hosts:
                - { dsn: localhost, port: 11211 }
            options:
                prefix_key: lingo_general_

This results in:

ErrorException: Warning: Memcached::setOption(): error setting memcached option in /srv/http/lingo/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php line 1087

 in /srv/http/lingo/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php line 1087
at ErrorHandler->handle('2', 'Memcached::setOption(): error setting memcached option', '/srv/http/lingo/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php', '1087', array('option' => '15', 'value' => '0', 'start' => '1365523204.4116', 'name' => 'setOption'))
at Memcached->setOption('15', '0') in /srv/http/lingo/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php line 1087
at LoggingMemcache->setOption('15', '0') in /srv/http/lingo/app/cache/dev/appDevDebugProjectContainer.php line 2269
at appDevDebugProjectContainer->getMemcache_GeneralService() in /srv/http/lingo/app/bootstrap.php.cache line 211
...

If I remove the prefix_key, everything is fine.

You have requested a non-existent parameter "memcache.session_handler.auto_load".

Hello,

the documentation states that :

This bundle also provides support for storing session data on Memcache servers. To enable session support you will have to enable it through the session key (auto_load is true by default). Note that the only required subkey of the session support is pool (a valid pool). You can also specify a key prefix and a ttl.

But if you don't want to enable the session and disable this option you get this error :

ParameterNotFoundException in ParameterBag.php line 106:
You have requested a non-existent parameter "memcache.session_handler.auto_load". Did you mean this: "memcache.session_handler.class"?

Here is my configuration in config.yml :

lsw_memcache:
    pools:
         default:
           servers:
                - { host: localhost, tcp_port: 11211 }
            options:
                allow_failover: true
                max_failover_attempts: 20
                default_port: 11211
                chunk_size: 32768
                protocol: ascii
                hash_strategy: consistent
                hash_function: crc32
                redundancy: true
                session_redundancy: 2
                compress_threshold: 20000
                lock_timeout: 15
#        sessions:
#            servers:
#                - { host: localhost, tcp_port: 11212 }
#    session:
#        auto_load: false
#        pool: sessions

I'm using Symfony version 2.7.1.

Thanks in advance for pointing out any obvious mistake i would have done :)

session locking issue

The recent change to session locking being set to default would cause httpd server becoming unresponsive.

Have a current setup where 2 servers are using memcached to share session information. If server A a User starts printing a PDF file then the server B would become unresponsive until server A finish processing the PDF file (note server A is also un-useable).

Setting session locking to false solve this issue. Unsure why session locking would cause this issue though.

Strict standards broken

Strict standards: Declaration of Lsw\MemcacheBundle\Cache\LoggingMemcache::get() should be compatible with Memcached::get($key, $cache_cb = NULL, &$cas_token = NULL, &$udf_flags = NULL) in /home/damian/PhpstormProjects/shop-new/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php on line 1358

Strict standards: Declaration of Lsw\MemcacheBundle\Cache\LoggingMemcache::getByKey() should be compatible with Memcached::getByKey($server_key, $key, $cache_cb = NULL, &$cas_token = NULL, &$udf_flags = NULL) in /home/damian/PhpstormProjects/shop-new/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php on line 1358

Strict standards: Declaration of Lsw\MemcacheBundle\Cache\LoggingMemcache::getMulti() should be compatible with Memcached::getMulti(array $keys, &$cas_tokens = NULL, $flags = NULL, &$udf_flags = NULL) in /home/damian/PhpstormProjects/shop-new/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php on line 1358

Strict standards: Declaration of Lsw\MemcacheBundle\Cache\LoggingMemcache::getMultiByKey() should be compatible with Memcached::getMultiByKey($server_key, array $keys, &$cas_tokens = NULL, $flags = NULL, &$udf_flags = NULL) in /home/damian/PhpstormProjects/shop-new/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php on line 1358

PHP Version:

PHP 5.5.16-1+deb.sury.org~trusty+1 (cli) (built: Aug 25 2014 10:24:59) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

Composer Update Not Seeing Memcache PHP Extension

I am going through the installation set up, and when I get to the $ composer update .. I get this error:

$ composer update leaseweb/memcache-bundle

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - leaseweb/memcache-bundle v1.2.4 requires ext-memcached >=1.0 -> the requested PHP extension memcached is missing from your system.
    - leaseweb/memcache-bundle v1.2.3 requires ext-memcached >=1.0 -> the requested PHP extension memcached is missing from your system.
    - leaseweb/memcache-bundle v1.2.2 requires ext-memcached >=1.0 -> the requested PHP extension memcached is missing from your system.
    - leaseweb/memcache-bundle v1.2.1 requires ext-memcached >=1.0 -> the requested PHP extension memcached is missing from your system.
    - leaseweb/memcache-bundle v1.2.0 requires ext-memcached >=1.0 -> the requested PHP extension memcached is missing from your system.
    - leaseweb/memcache-bundle v1.1.3 requires ext-memcached >=1.0 -> the requested PHP extension memcached is missing from your system.
    - leaseweb/memcache-bundle v1.1.2 requires ext-memcached >=1.0 -> the requested PHP extension memcached is missing from your system.
    - leaseweb/memcache-bundle v1.1.1 requires ext-memcached >=1.0 -> the requested PHP extension memcached is missing from your system.
    - leaseweb/memcache-bundle v1.1.0 requires ext-memcached >=1.0 -> the requested PHP extension memcached is missing from your system.
    - leaseweb/memcache-bundle v1.0.0 requires ext-memcached >=1.0 -> the requested PHP extension memcached is missing from your system.
    - Installation request for leaseweb/memcache-bundle * -> satisfiable by leaseweb/memcache-bundle[v1.0.0, v1.1.0, v1.1.1, v1.1.2, v1.1.3, v1.2.0, v1.2.1, v1.2.2, v1.2.3, v1.2.4].

However I have confirmed through multiple ways that Memcache is set up (both server and client), see this as proof:

$ php -i | grep memcache
memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 8192 => 8192
memcache.default_port => 11211 => 11211
memcache.default_timeout_ms => 1000 => 1000
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => standard => standard
memcache.max_failover_attempts => 20 => 20

I've tried several different mechanisms, articles, blogs, but nothing seems to work? Any help would be greatly appreciated.

Thanks,
Josh

Memcache connections are left open after page load

After every page load the memcached Curr Connections is increased and when it hits Max Connection the whole website stop working because of connection timeout.

My config.yml:

lsw_memcache:
    doctrine:
        metadata_cache:
            client: default
            entity_manager: default          # the name of your entity_manager connection
            document_manager: default        # the name of your document_manager connection
            prefix: %cache_prefix%
        result_cache:
            client: default
            entity_manager: default          # you may specify multiple entity_managers
            prefix: %cache_prefix%
        query_cache:
            client: default
            entity_manager: default
            prefix: %cache_prefix%
    clients:
        default:
            hosts:
              - { dsn: localhost, port: 11211 }

FOS User / Extended entity result cache problem

Hi,
i am not sure where the problem is but i noticed that when i try to use extended fos user entity i retrieve from cache result which contains only entity base fields (my extended ones are null).
I am doing it this way:

$cacheKey = 'blog_articles'
$result = $this->getCache($cacheKey);
        if($result == false){

$query = $em
                        ->createQueryBuilder()
                        ->select('partial a.{id,slug,title,lead,status,youtube_code,publish_at}, partial u.{id, firstname, lastname, image, slug}')
                        ->from('MyBundle:Article','a')
                        ->leftJoin('a.author','u')
                        [ ... ];

$result = $query->getQuery()->getResult();
$this->setCache($cacheKey, $result, 0, 7200);
}

where setCache and getCache are my methods to write/read cache to memcache pool. When i clear cache i see all the information about article author, but when i check saved cache fields from extended fos user entity (firstname, lastname, image, slug) are nulls (in my entity declaration property variables are 'protected'). Anything i do wrong?

I tried to add fos_user entity manager in doctrine.result_cache

result_cache:
            pool: myPoolId
            entity_manager: [default, fos_user.entity_manager]  # you may specify multiple entity_managers
            prefix: "result_"                # you may specify a prefix for the entries

but it didnt work. When i remove whole memcache doctrine configuration i also dont see those entity properties in cache.

Session cache dos not work

I've installed and configured LswMemcacheBundle acording with the documentation:

Modified app/AppKernel.php, added the lsw_memcache to the config.yml

lsw_memcache:
    session:
        client: sessions
        prefix: "session_"
        ttl: 7200
        locking: true
        spin_lock_wait: 150000
    clients:
        default:
            hosts:
              - { dsn: localhost, port: 11211 }
        sessions:
            hosts:
              - { dsn: localhost, port: 11211 }

And the memcached server is working as expected

$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
quit
Connection closed by foreign host.

But the sessions aren't stored in the memcached. I've seen in the known issues that debug doesn't show the memcached hits/writes... for session, but anyway, I've debuged the LockingSessionHandler and is never accessed (even instantiated).

Am I missing something?

Thank you very much for your help.

Undefined property: Lsw\MemcacheBundle\Cache\AntiDogPileMemcache::$memcache

Hi!

I use your bundle to use memcached in a Symfony2 application but when i try to deploy it on a server i have this error message :

Undefined property: Lsw\MemcacheBundle\Cache\AntiDogPileMemcache::$memcache in /var/www/selling/releases/20140123102411/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcacheTemplate.php on line 24

PHP Fatal error: Call to a member function getServerList() on a non-object in /var/www/selling/releases/20140123102411/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcacheTemplate.php on line 24

Would not it be "$this->initialize = count($this->getServerList())==0;" instead of "$this->initialize = count($this->memcache->getServerList())==0;"

Thanks

Composer warning - ambiguous class resolution

Warning: Ambiguous class resolution, "Memcached" was found in both "/ho
me/myuser/myproject/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/
Resources/codegen/memcached-2.1.0/memcached-api.php" and "/home/myuser/
myproject/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Resources/
codegen/memcached-1.0.2/memcached-api.php", the first will be used.  
Warning: Ambiguous class resolution, "MemcachedException" was found in 
both "/home/myuser/myproject/vendor/leaseweb/memcache-bundle/Lsw/Memcac
heBundle/Resources/codegen/memcached-2.1.0/memcached-api.php" and "/hom
e/myuser/myproject/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/R
esources/codegen/memcached-1.0.2/memcached-api.php", the first will be 
used.  
Warning: Ambiguous class resolution, "Memcached" was found in both "/ho
me/myuser/myproject/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/
Resources/codegen/memcached-2.1.0/memcached-api.php" and "/home/myuser/
myproject/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Resources/
codegen/memcached-2.2.0/memcached-api.php", the first will be used.  
Warning: Ambiguous class resolution, "MemcachedException" was found in 
both "/home/myuser/myproject/vendor/leaseweb/memcache-bundle/Lsw/Memcac
heBundle/Resources/codegen/memcached-2.1.0/memcached-api.php" and "/hom
e/myuser/myproject/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/R
esources/codegen/memcached-2.2.0/memcached-api.php", the first will be 
used.  
Warning: Ambiguous class resolution, "Memcached" was found in both "/ho
me/myuser/myproject/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/
Resources/codegen/memcached-2.1.0/memcached-api.php" and "/home/myuser/
myproject/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Resources/
codegen/memcached-2.0.1/memcached-api.php", the first will be used.  
Warning: Ambiguous class resolution, "MemcachedException" was found in 
both "/home/myuser/myproject/vendor/leaseweb/memcache-bundle/Lsw/Memcac
heBundle/Resources/codegen/memcached-2.1.0/memcached-api.php" and "/hom
e/myuser/myproject/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/R
esources/codegen/memcached-2.0.1/memcached-api.php", the first will be 
used.

Argument 3 passed to Lsw\MemcacheBundle\DataCollector\MemcacheDataCollector::addClient() must be an instance of Lsw\MemcacheBundle\Cache\LoggingMemcacheInterface, instance of Lsw\MemcacheBundle\Cache\AntiDogPileMemcache given

When installing from either * or dev-master:

ContextErrorException: Catchable Fatal Error: Argument 3 passed to Lsw\MemcacheBundle\DataCollector\MemcacheDataCollector::addClient() must be an instance of Lsw\MemcacheBundle\Cache\LoggingMemcacheInterface, instance of Lsw\MemcacheBundle\Cache\AntiDogPileMemcache given, called in /home/josh/web/example/app/cache/dev/appDevDebugProjectContainer.php on line 2943 and defined in /home/josh/web/example/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/DataCollector/MemcacheDataCollector.php line 40

in /home/josh/web/example/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/DataCollector/MemcacheDataCollector.php line 40 at ErrorHandler->handle('4096', 'Argument 3 passed to Lsw\MemcacheBundle\DataCollector\MemcacheDataCollector::addClient() must be an instance of Lsw\MemcacheBundle\Cache\LoggingMemcacheInterface, instance of Lsw\MemcacheBundle\Cache\AntiDogPileMemcache given, called in /home/josh/web/example/app/cache/dev/appDevDebugProjectContainer.php on line 2943 and defined', '/home/josh/web/example/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/DataCollector/MemcacheDataCollector.php', '40', array('name' => 'default', 'options' => array('compression' => 'false', 'serializer' => ''php'', 'prefix_key' => '''', 'hash' => ''default'', 'distribution' => ''modula'', 'libketama_compatible' => 'false', 'buffer_writes' => 'false', 'binary_protocol' => 'false', 'no_block' => 'false', 'tcp_nodelay' => 'false', 'socket_send_size' => 'NULL', 'socket_recv_size' => 'NULL', 'connect_timeout' => '1000', 'retry_timeout' => '0', 'send_timeout' => '0', 'recv_timeout' => '0', 'poll_timeout' => '1000', 'cache_lookups' => 'false', 'server_failure_limit' => '0'))) in /home/josh/web/example/vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/DataCollector/MemcacheDataCollector.php line 40 at MemcacheDataCollector->addClient('default', array('compression' => 'false', 'serializer' => ''php'', 'prefix_key' => '''', 'hash' => ''default'', 'distribution' => ''modula'', 'libketama_compatible' => 'false', 'buffer_writes' => 'false', 'binary_protocol' => 'false', 'no_block' => 'false', 'tcp_nodelay' => 'false', 'socket_send_size' => 'NULL', 'socket_recv_size' => 'NULL', 'connect_timeout' => '1000', 'retry_timeout' => '0', 'send_timeout' => '0', 'recv_timeout' => '0', 'poll_timeout' => '1000', 'cache_lookups' => 'false', 'server_failure_limit' => '0'), object(AntiDogPileMemcache)) in /home/josh/web/example/app/cache/dev/appDevDebugProjectContainer.php line 2943 at appDevDebugProjectContainer->getMemcache_DataCollectorService() in /home/josh/web/example/app/bootstrap.php.cache line 2063 at Container->get('memcache.data_collector') in /home/josh/web/example/app/cache/dev/appDevDebugProjectContainer.php line 3532 at appDevDebugProjectContainer->getProfilerService() in /home/josh/web/example/app/bootstrap.php.cache line 2063 at Container->get('profiler') in /home/josh/web/example/app/cache/dev/appDevDebugProjectContainer.php line 3547 at appDevDebugProjectContainer->getProfilerListenerService() in /home/josh/web/example/app/bootstrap.php.cache line 2063 at Container->get('profiler_listener') in /home/josh/web/example/app/cache/dev/classes.php line 1858 at ContainerAwareEventDispatcher->lazyLoad('kernel.exception') in /home/josh/web/example/app/cache/dev/classes.php line 1826 at ContainerAwareEventDispatcher->getListeners('kernel.exception') in /home/josh/web/example/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php line 215 at TraceableEventDispatcher->preProcess('kernel.exception') in /home/josh/web/example/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php line 107 at TraceableEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in /home/josh/web/example/app/bootstrap.php.cache line 3008 at HttpKernel->handleException(object(ContextErrorException), object(Request), '1') in /home/josh/web/example/app/bootstrap.php.cache line 2944 at HttpKernel->handle(object(Request), '1', true) in /home/josh/web/example/app/bootstrap.php.cache line 3087 at ContainerAwareHttpKernel->handle(object(Request), '1', true) in /home/josh/web/example/app/bootstrap.php.cache line 2337 at Kernel->handle(object(Request)) in /home/josh/web/example/web/app_dev.php line 28

Bug multiple servers memcached

Hello,

I have configured your bundle with multiple servers for use in doctrine result cache but when I get the memcached server list I have got this :


array (size=18)
  0 => 
    array (size=2)
      'host' => string '192.168.60.41' (length=13)
      'port' => int 11211
  1 => 
    array (size=2)
      'host' => string '192.168.60.42' (length=13)
      'port' => int 11211
  2 => 
    array (size=2)
      'host' => string '192.168.60.51' (length=13)
      'port' => int 11211
  3 => 
    array (size=2)
      'host' => string '192.168.60.41' (length=13)
      'port' => int 11211
  4 => 
    array (size=2)
      'host' => string '192.168.60.42' (length=13)
      'port' => int 11211
  5 => 
    array (size=2)
      'host' => string '192.168.60.51' (length=13)
      'port' => int 11211
  6 => 
    array (size=2)
      'host' => string '192.168.60.41' (length=13)
      'port' => ....

This is my config.yml:


lsw_memcache:
    clients:
        default:
            persistent_id: default
            hosts:
                - { dsn: 192.168.60.41, port: 11211, weight: 0 }
                - { dsn: 192.168.60.42, port: 11211, weight: 0 }
                - { dsn: 192.168.60.51, port: 11211, weight: 0 }
            options:
                prefix_key: ""
                compression: true
                serializer: json

    doctrine:
        result_cache:
            client: default
            entity_manager: default
            document_manager: default

What I'm doing wrong ?

Memcached session fallback

Perhaps this is more a php related problem.
I set memcache for session as:

lsw_memcache:
    session:
        client: default

All is fine when my memcached server is on.
However, when it is off I am not able to use sessions anymore.

Is there any way to set this with some kind of fallback, so that when the memcached server is gone it would use the default filesystem until it is back again?

Add LswMemcache to multiple Doctrine entity manager

Documentation already gives information about how to add LswMemcacheBundle support on Doctrine (see https://github.com/LeaseWeb/LswMemcacheBundle#doctrine-support)
But even if this is well handled for default entity manager, it seems it does not work for multiple entity managers :

When using executeCacheQuery() we get :
Trying to cache a query but no result driver is configured.

Another way to check :

dump($this->get('doctrine')->getManager('metrics')->
    getConnection()->getConfiguration()->getResultImpl()); 
// dump NULL

Copy of YAML :

lsw_memcache:
    pools:
        default:
            servers:
              - { host: 127.0.0.1, tcp_port: 11211 }
    doctrine:
        metadata_cache:
            pool: default
            entity_manager: [default, metrics]
            document_manager: default
        result_cache:
            pool: default
            entity_manager: [default, metrics]
            prefix: "result_"
        query_cache:
            pool: default
            entity_manager: [default, metrics]

If we try to add the cache class ourself, we end with an error :

$cache = $this->get('memcache.default');
$config = $this->get('doctrine')->getManager('metrics')->getConnection()->getConfiguration();
$config->setResultCacheImpl($cache);

This gives this error :
Argument 1 passed to Doctrine\DBAL\Configuration::setResultCacheImpl() must implement interface Doctrine\Common\Cache\Cache, instance of Lsw\MemcacheBundle\Cache\AntiDogPileMemcache given.

tags?

It would be nice to have some tags.
This way current development work can be separated from the stable release.

Also if there are any changes in symfony 2.3 that would affect the bundle, a tag would be a must.

Class 'MemcachePool' not found in /vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php on line 4

Hi

I get this error : Class 'MemcachePool' not found in /vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php on line 4

But everything seem to be set correctly (php -i):

.....
memcache

memcache support => enabled
Version => 3.0.8
Revision => $Revision: 329835 $

Directive => Local Value => Master Value
memcache.allow_failover => 1 => 1
memcache.chunk_size => 32768 => 32768
memcache.compress_threshold => 20000 => 20000
memcache.default_port => 11211 => 11211
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => consistent => consistent
memcache.lock_timeout => 15 => 15
memcache.max_failover_attempts => 20 => 20
memcache.protocol => ascii => ascii
memcache.redundancy => 1 => 1
memcache.session_redundancy => 2 => 2
......

And my config_dev.yml:

lsw_memcache:
    session:
        pool: default
    pools:
        default:
            servers:
              - { host: localhost, tcp_port: 11211  }

I get also that during a php app/console cache:clear:

Clearing the cache for the dev environment with debug true
dyld: lazy symbol binding failed: Symbol not found: _mmc_queue_free
  Referenced from: /usr/local/opt/php56-memcache/memcache.so
  Expected in: flat namespace

dyld: Symbol not found: _mmc_queue_free
  Referenced from: /usr/local/opt/php56-memcache/memcache.so
  Expected in: flat namespace

$ telnet localhost 11211 give:

Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
telnet: Unable to connect to remote host

I use leaseweb/memcache-bundle v2.1.2, PHP 5.6.11, Symfony 2.6.9 and Homebrew 0.9.5

Thanks for help

ErrorException after update

ErrorException: Runtime Notice: Declaration of Lsw\MemcacheBundle\Cache\LoggingMemcache::increment() should be compatible with Memcached::increment($key, $offset = NULL, $initial_value = NULL, $expiry = NULL) in vendor/leaseweb/memcache-bundle/Lsw/MemcacheBundle/Cache/LoggingMemcache.php line 7

PHP 5.4.6-1ubuntu1.2
php5-memcached 2.0.1-6

require memcached php extension?

I've tried to install the bundle, but it seems the memcached php extension is a requirement.

What about the users of a shared hosting that does not provide memcached extension?

IMHO this should be a suggestion rather than requirement.

The requirement has to be set for the ext-memcache, which provides the Memcache class.

> composer require leaseweb/memcache-bundle dev-master
composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for leaseweb/memcache-bundle dev-master -> satisfiable by leaseweb/memcache-bundle dev-master.
    - leaseweb/memcache-bundle dev-master requires ext-memcached >=1.0 -> the requested PHP extension memcached is missing from your system.


Installation failed, reverting composer.json to its original content.

Symfony reporting 2x memory usage

Hello! I am just starting out using Memcached with Doctrine (in Symfony) and I've gone straight to using your bundle to help me do that.

I am testing the Memcached caching on an API call which makes just 4 queries but returns a lot of data. This data is parsed and output as JSON. I intend to simply cache those 4 queries.

Straight away I am experiencing something surprising. Symfony's debug bar is now reporting roughly twice the memory usage (~118MB) than when I am not using Memcached (~55MB). My question is simply this: is this normal? I was actually expecting much LESS memory to be reported as being used because the DB wouldn't be hit. Can anyone explain why it virtually doubled?

I presume the DB memory is being saved (I'm not sure how to measure this?) but why has this led to an increase in PHP memory?

My config is a virtual copy and paste of your default except I don't want to cache my sessions:

lsw_memcache:
#    session:
#        client: default
    doctrine:
        metadata_cache:
            client: default
            entity_manager: default          # the name of your entity_manager connection
            document_manager: default        # the name of your document_manager connection
        result_cache:
            client: default
            entity_manager: default
            prefix: "result_"                # you may specify a prefix for the entries
        query_cache:
            client: default
            entity_manager: default
    clients:
        default:
            hosts:
              - { dsn: localhost, port: 11211 }

Thank you for any light you can shed on this.

Cache the session

Hi, I try to cache the session in my symfony2 web; but i got this message * Notice: MemcachePool::add():*
I use default configuration.

Sessions no longer stored in memcache

Ever since the update from v1.2.13 to v1.2.14 sessions are no longer stored in memcache by solely defining a client for lsw_memcache. This is due to the following commit: df0a643

In Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension::registerSessionConfiguration() the session.handler alias is always set to the session handler set at that moment. (By default this is session.handler.native_file). This part is executed before this bundle's EnableSessionSupport compiler pass and therefore the compilerpass will never set the session.handler alias.

Undoing that commit will however not solve all the problems. For instance, when setting a value for metadata_update_threshold, a session handler wrapper is defined as session handler. Without the previously mentioned commit, the EnableSessionSupport compiler pass will overwrite the session handler while the expected behavour is that the WriteCheckSessionHandler would wrap the LockingSessionHandler. (And even when this bundle would not overwrite the session handler, the wrong session handler would be wrapped.)

Adding the following to config.yml solves the entire problem:

services:
    session.handler:
        alias: memcache.session_handler

All in all I get the idea that automatic registration of memcache.session_handler as session handler creates more problems than it solves. At the moment, the compiler pass is actually doing nothing at all. I believe it is better to instruct the users to explicitly set the session.handler. Its just a small step and this not only makes it clearer for the user what exactly is going on, it also lets the memcache session handler hook better into the whole environment.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.