PHPackages                             aequasi/memcached-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. aequasi/memcached-bundle

ActiveLibrary[Caching](/categories/caching)

aequasi/memcached-bundle
========================

Memcached Bundle

1.5.6(12y ago)1382.6k9[1 PRs](https://github.com/aequasi/memcached-bundle/pulls)ApachePHPPHP &gt;=5.3.0

Since Apr 30Pushed 8y ago3 watchersCompare

[ Source](https://github.com/aequasi/memcached-bundle)[ Packagist](https://packagist.org/packages/aequasi/memcached-bundle)[ Docs](https://github.com/aequasi/memcached-bundle)[ RSS](/packages/aequasi-memcached-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (27)Used By (0)

memcached-bundle [![Build Status](https://camo.githubusercontent.com/6478ff860d674b9d61f2038b406c48bcbe3270de7c77a0ef67f0259ccea4ba1a/68747470733a2f2f7472617669732d63692e6f72672f616571756173692f6d656d6361636865642d62756e646c652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/aequasi/memcached-bundle)
========================================================================================================================================================================================================================================================================================================================

[](#memcached-bundle-)

THIS BUNDLE IS DEPRECATED
=========================

[](#this-bundle-is-deprecated)

Moving forward, use the [`php-cache`](http://www.php-cache.com) library

If you insist.....
------------------

[](#if-you-insist)

### Memcached Bundle for Symfony 2

[](#memcached-bundle-for-symfony-2)

Creates a service in Symfony 2 that can also be used with doctrines `result_cache_driver` and `query_cache_driver`.

There is also functionality for having a key map stored in mysql. Basically, it stores the keys, the size of the value, how long the lifetime is, and when it should expire.

Should work in all versions of symfony, and php 5.3

Requires the php5-memcached extension (Works with amazons elasticache extension as well)

### Requirements

[](#requirements)

- PHP 5.3.x or 5.4.x
- php5-memcached 1.x or 2.x (this is the PHP "memcached" extension that uses "libmemcached")
- (Works with amazons elasticache extension as well)

[![screenshot](https://camo.githubusercontent.com/1eabc6b8b685d0d2ee97bbc5ccbf7f1f9905648d8aa9a34db626eb6add4071b6/687474703a2f2f7777772e6c656173657765626c6162732e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031332f30332f6d656d63616368655f64656275672e706e67)](https://camo.githubusercontent.com/1eabc6b8b685d0d2ee97bbc5ccbf7f1f9905648d8aa9a34db626eb6add4071b6/687474703a2f2f7777772e6c656173657765626c6162732e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031332f30332f6d656d63616368655f64656275672e706e67)

### To Install

[](#to-install)

```
	composer.phar require aequasi/memcached-bundle dev-master
	// Replace dev master with what ever version you want
```

Add the bundle to app/AppKernerl.php

```
$bundles(
    ...
       new Aequasi\Bundle\MemcachedBundle\AequasiMemcachedBundle(),
    ...
);
```

Then add parameters (probably in config.yml) for your servers, and options

```
aequasi_memcached:
    clusters:
        default:
            prefix: 'result_' # Optional
            persistent_id: cluser_1
            hosts:
              - { host: localhost, port: 11211, weight: 100 }
            options:
                compression: true
                libketama_compatible: true
                connect_timeout: 50
                recv_timeout: 500000
                send_timeout: 500000
                poll_timeout: 50
                retry_timeout: 5
                no_block: true
                server_failure_limit: 7
                tcp_no_delay: true
            keyMap:
                enabled: %memcached.keymap.enabled%
                connection: default
```

There are also options that you can specify above. You can get the list of options by running

```
php app/console config:dump aequasi_memcached
```

#### Doctrine

[](#doctrine)

This bundle allows you to use its services for Doctrine's caching methods of metadata, result, and query.

If you want doctrine to use this as the result and query cache, add this

```
aequasi_memcached:
    doctrine:
        metadata:
            cluster: default
            entity_manager: default          # the name of your entity_manager connection
            document_manager: default        # the name of your document_manager connection
        result:
            cluster: default
            entity_manager: [default, read]  # you may specify multiple entity_managers
        query:
            cluster: default
            entity_manager: default
```

#### Session

[](#session)

This bundle even allows you to store your session data in one of your memcache clusters. To enable:

```
aequasi_memcached:
    session:
        cluster: default
        prefix: "session_"
        ttl: 7200
```

#### Anti Stampede

[](#anti-stampede)

Taken from Lws\\MemcacheBundle

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 from cache the cache value. You have about 5000 requests per second and 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 &gt; 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' and is very unwelcome during peek 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() and setAdp() functions that can be used as replacements for the normal get and set.

Please note:

Anti Stampede might not be needed if you have low amount of hits or when calculating the new value goes relatively fast. Anti Stampede might not be needed if you can break up the big calculation into smaller, maybe even with different timeouts for each part. Anti Stampede 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. Anti Stampede's "getAdp" and Anti Stampede "setAdp" are more expensive than the normal "get" and "set", slowing down all cache hits. Anti Stampede 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.

### To Use

[](#to-use)

You can use the default memcached functions, doctrine's `useResultCache` and `useQueryCache`, or you can use the `cache` function. Heres an example

```
use Aequasi\Bundle\MemcachedBundle\Cache\AntiStampedeMemcached as Cache;

/** @var $em \Doctrine\ORM\EntityManager */
$data = $this->get( 'memcached.default' )->cache(
	'somekey',
	function( ) use( $em, $color ) {
		$repo = $em->getRepository( 'AcmeDemoBundle:Fruit' );
		return $repo->findBy( array( 'color' => $color ) );
	}, Cache::THIRTY_MINUTE
);
```

This will attempt to grab `somekey`. If it cant find it, it will run the closure, and cache it for 30 minutes, as `somekey`. You can use a closure here, or a callable, or even just a scalable type.

There are also three commands (might add more later), for getting, setting, and deleting items in cache.

```
php app/console memcached:get cluster key

php app/console memcached:set cluster key value [lifetime=60]

php app/console memcached:delete cluster key

php app/console memcached:clear [cluster] # If cluster is specified, might not clear all the keys for the cluster. Uses http://www.php.net/manual/en/memcached.getallkeys.php

php app/console memcached:statistics cluster

php app/console memcached:initialize:keymap cluster (required if using the keymap)
```

### Need Help?

[](#need-help)

Create an issue if you've found a bug,

or email me at

[![Bitdeli Badge](https://camo.githubusercontent.com/dff183f4e9005a74bf3068f6e97ce662fefb3414411b2f67290de154c1630e49/68747470733a2f2f64327765637a68766c38323376302e636c6f756466726f6e742e6e65742f616571756173692f6d656d6361636865642d62756e646c652f7472656e642e706e67)](https://bitdeli.com/free "Bitdeli Badge")

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Recently: every ~16 days

Total

25

Last Release

4654d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9cf67675d97e63f6ff9e7fed55f35502b24cd834081806a6731229117c0630bb?d=identicon)[aequasi](/maintainers/aequasi)

---

Top Contributors

[![cryptiklemur](https://avatars.githubusercontent.com/u/896295?v=4)](https://github.com/cryptiklemur "cryptiklemur (124 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![leafpeak](https://avatars.githubusercontent.com/u/1653998?v=4)](https://github.com/leafpeak "leafpeak (1 commits)")

---

Tags

phpmemcached

### Embed Badge

![Health badge](/badges/aequasi-memcached-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/aequasi-memcached-bundle/health.svg)](https://phpackages.com/packages/aequasi-memcached-bundle)
```

###  Alternatives

[clickalicious/phpmemadmin

phpMemAdmin - Bringing Memcached to the web

5076.0k](/packages/clickalicious-phpmemadmin)[alekseykorzun/memcached-wrapper-php

Optimized PHP 5 wrapper for Memcached extension that supports dog-piling, igbinary and local storage

2984.6k1](/packages/alekseykorzun-memcached-wrapper-php)[clickalicious/memcached.php

Memcached.php - Plain vanilla PHP Memcached client with full support of Memcached protocol.

2973.7k5](/packages/clickalicious-memcachedphp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
