PHPackages                             myoperator/libmemcached - 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. myoperator/libmemcached

ActiveLibrary[Caching](/categories/caching)

myoperator/libmemcached
=======================

Memcached library for generic use

090PHP

Since Sep 10Pushed 6y agoCompare

[ Source](https://github.com/myoperator/libmemcached)[ Packagist](https://packagist.org/packages/myoperator/libmemcached)[ RSS](/packages/myoperator-libmemcached/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Myoperator Libmemcached
=======================

[](#myoperator-libmemcached)

This library is intended to be used as a basic `memcached` connector with few adddons as required in myopeator projects. Otherwise, this is same as using `memcached` library.

Features
--------

[](#features)

- Namespaces and defines
- PSR-4 autoloading compliant structure
- Unit-Testing with PHPUnit
- Easy to use to any framework or even a plain php file

Installation
------------

[](#installation)

You can easily install this package by adding following section in your composer.json:

```
"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/myoperator/libmemcached.git"
        }
    ]

```

and then doing: `composer require myoperator/libmemcached:dev-master`

or by adding following to your composer.json:

```
  "require": {
        "myoperator/libmemcached": "dev-master"
  }

```

The `composer.json` will look like

```
{
    "require": {
        "myoperator/libmemcached": "dev-master"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/myoperator/libmemcached.git"
        }
    ]
}
```

Usage
-----

[](#usage)

1. Include `vendor/autoload` in your project

```
   include_once 'vendor/autoload.php';
```

2. Configure the package

```
  use \MyOperator\LibMemcached;

  $memcache = LibMemcached::getInstance(['host' => 'localhost', 'port' => '11211']); //defaults to 127.0.0.1:11211

  // Get value
  $val = $memcache->get('a'); // Null
  $memcache->set('a', 1); // a = 1
  $memcache->increment('a'); // a =2
  $memcache->decrement('a'); // a =1
```

Mocking
-------

[](#mocking)

Since this is a memcache library, hence any code using this library, tends to avoid actual network requests (which this library makes) for its unit tests.

To prevent those network scenarios, this library conviniently provides a mocking instance to test some of the memcached's most used methods, which includes:

- get
- set
- increment
- decrement
- addServer
- getVersion

To mock this library in any framework, you can simple use this sample code

```
$mockedMemcacheInstance = \MyOperator\LibMemcached::getMockInstance();

// Now you can pretty much do anything you'd expect with memcache, to simulate unit test behaviours
// For example, setting and getting values is easy :)

$mockedMemcacheInstance->set('key', 'val');

$mockedMemcacheInstance->get('key'); //returns 'val'
```

Please see the `tests/unit` directory to see what methods can be mocked and how to use the mocks.

TODO
----

[](#todo)

- Add `phpdoc` documentation

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/13e9ef65aca6c94519bd96b589043034c126905d9d219f0d1d2362c9a06482ff?d=identicon)[codeasashu](/maintainers/codeasashu)

---

Top Contributors

[![codeasashu](https://avatars.githubusercontent.com/u/1492350?v=4)](https://github.com/codeasashu "codeasashu (7 commits)")

---

Tags

memcachedmockingphp

### Embed Badge

![Health badge](/badges/myoperator-libmemcached/health.svg)

```
[![Health](https://phpackages.com/badges/myoperator-libmemcached/health.svg)](https://phpackages.com/packages/myoperator-libmemcached)
```

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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