{"id":16675801,"url":"https://github.com/seregazhuk/php-react-memcached","last_synced_at":"2025-08-24T05:11:47.502Z","repository":{"id":56860097,"uuid":"106166425","full_name":"seregazhuk/php-react-memcached","owner":"seregazhuk","description":"Asynchronous Memcached PHP Client for ReactPHP ecosystem","archived":false,"fork":false,"pushed_at":"2019-12-22T12:13:45.000Z","size":213,"stargazers_count":26,"open_issues_count":5,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-03T23:11:30.815Z","etag":null,"topics":["memcached-clients","php","reactphp"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seregazhuk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-08T10:05:44.000Z","updated_at":"2023-12-24T22:26:54.000Z","dependencies_parsed_at":"2022-08-29T19:02:09.134Z","dependency_job_id":null,"html_url":"https://github.com/seregazhuk/php-react-memcached","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/seregazhuk/php-react-memcached","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seregazhuk%2Fphp-react-memcached","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seregazhuk%2Fphp-react-memcached/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seregazhuk%2Fphp-react-memcached/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seregazhuk%2Fphp-react-memcached/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seregazhuk","download_url":"https://codeload.github.com/seregazhuk/php-react-memcached/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seregazhuk%2Fphp-react-memcached/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271796072,"owners_count":24822886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["memcached-clients","php","reactphp"],"created_at":"2024-10-12T13:07:51.299Z","updated_at":"2025-08-24T05:11:47.440Z","avatar_url":"https://github.com/seregazhuk.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"logo.png\" alt=\"ReactPHP Memcached Client\"\u003e\n\u003c/p\u003e\n\nAsynchronous Memcached PHP Client for [ReactPHP](http://reactphp.org/) ecosystem.\n\n[![Build Status](https://travis-ci.org/seregazhuk/php-react-memcached.svg?branch=master)](https://travis-ci.org/seregazhuk/php-react-memcached)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/seregazhuk/php-react-memcached/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/seregazhuk/php-react-memcached/?branch=master)\n[![Maintainability](https://api.codeclimate.com/v1/badges/15741538d0851e75a179/maintainability)](https://codeclimate.com/github/seregazhuk/php-react-memcached/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/15741538d0851e75a179/test_coverage)](https://codeclimate.com/github/seregazhuk/php-react-memcached/test_coverage)\n[![StyleCI](https://styleci.io/repos/106166425/shield?branch=master)](https://styleci.io/repos/106166425)\n\n**Table of Contents**\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n- [Server Address](#server-address)\n- [Client](#client)\n- [Retrieval Commands](#retrieval-commands)\n    - [Get](#get)\n- [Storage Commands](#storage-commands)\n    - [Set](#set)\n    - [Add](#add)\n    - [Replace](#replace)\n- [Delete Command](#delete-command)\n- [Increment/Decrement Commands](#increment/decrement-commands)\n    - [Increment](#increment)\n    - [Decrement](#decrement)\n- [Touch Command](#touch-command)\n- [Statistics Command](#statistics-command)\n- [Misc Commands](#misc-commands)\n    - [Flush all](#flush-all)\n    - [Version](#version)\n    - [Verbosity](#verbosity)       \n- [Connection Closing](#connection-closing)\n    - [End](#end())\n    - [Close](#close())\n- [Events Handling](#events-handling)\n- [Errors Handling](#errors-handling)\n\n## Installation\n\n### Dependencies\nLibrary requires PHP 5.6.0 or above.\n\nThe recommended way to install this library is via [Composer](https://getcomposer.org). \n[New to Composer?](https://getcomposer.org/doc/00-intro.md)\n\nSee also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.\n\n```\ncomposer require seregazhuk/react-memcached\n```\n\n## Quick Start\n\n```php\nrequire '../vendor/autoload.php';\n\nuse seregazhuk\\React\\Memcached\\Factory;\n\n$loop = React\\EventLoop\\Factory::create();\n$client = Factory::createClient($loop);\n\n$client-\u003eset('example', 'Hello world');\n\n$client-\u003eget('example')-\u003ethen(function ($data) {\n    echo $data . PHP_EOL; // Hello world\n});\n\n// Close the connection when all requests are resolved\n$client-\u003eend();\n\n$loop-\u003erun();\n```\nSee [other examples](https://github.com/seregazhuk/php-memcached-react/tree/master/examples).\n\n## Server address\n\nWhen creating a client via the factory you can specify server address as a second argument:\n\n```php\n$client = Factory::createClient($loop, 'localhost:11222');\n```\n\nIf the address is not specified the client uses default `localhost:11211`.\n\n## Asynchronous Execution\n\nFor each Memcached command a client has a method. All commands are executed asynchronously. The client stored pending \nrequests and once it receives the response from the server, it starts resolving these requests. That means that each \ncommand returns a promise. When the server executed a command and returns a response, the promise will be resolved \nwith this response. If there was an error, the promise will be rejected. \n\n## Retrieval Commands\n\n### Get\nGet value from key:\n\n```php\n$client\n    -\u003eget('some-key')\n    -\u003ethen(function ($data) {\n        echo \"Retreived value: \" . $data . PHP_EOL; \n    });\n```\n\n## Storage Commands\nFor `$flags` you can use PHP `MEMCACHE_COMPRESSED` constant to specify on-the-fly compression.\nIf the value was not stored indicate because condition for `add` or `replace` commands wasn’t met, or the item was in \na delete queue, the promise will be rejected with `FailedCommandException`.\n\n### Set\nStore key/value pair in Memcached:\n\n```php\n$client\n    -\u003eset('some-key', 'my-data')\n    -\u003ethen(function () {\n        echo \"Value was stored\" . PHP_EOL;\n    });\n    \n// advanced: with compression and expires in 30 seconds\n$client\n    -\u003eset('some-key', 'my-data', MEMCACHE_COMPRESSED, 30)\n    -\u003ethen(function () {\n        echo \"Value was stored\" . PHP_EOL;\n    });    \n```\n\n### Add\nStore key/value pair in Memcached, but only if the server **doesn’t** already hold data for this key:\n\n```php\n$client\n    -\u003eadd('name', 'test')\n    -\u003ethen(function() {\n        echo \"The value was added\" . PHP_EOL;\n    });\n    \n    \n// advanced: with compression and expires in 30 seconds\n$client\n    -\u003eadd('name', 'test', MEMCACHE_COMPRESSED, 30)\n    -\u003ethen(function() {\n        echo \"The value was added\" . PHP_EOL;\n    });    \n```\n\n### Replace\n\nStore key/value pair in Memcached, but only if the server already hold data for this key:\n```php\n$client\n    -\u003ereplace('name', 'test')\n    -\u003ethen(function(){\n        echo \"The value was replaced\" . PHP_EOL;\n    });\n \n// advanced    \n$client\n    -\u003ereplace('name', 'test', $flags, $exptime)\n    -\u003ethen(function(){\n        echo \"The value was replaced\" . PHP_EOL;\n    });    \n```\n\n## Delete Command\nDelete value by key from Memcached.\nIf the key doesn't exist or has been deleted the promise rejects with `FailedCommandException`:\n\n```php\n$client\n    -\u003edelete('name')\n    -\u003ethen(function(){\n        echo \"The value was deleted\" . PHP_EOL;\n});\n```\n\n## Increment/Decrement Commands\n\n### Increment\nIncrement value associated with key in Memcached, item **must** exist, increment command will not create it.\nThe limit of increment is the 64 bit mark. If key is not found, the promise will be rejected with `FailedCommandException`:\n\n```php\n$client\n    -\u003eincr('var', 2)\n    -\u003ethen(\n        function($data){\n            echo \"New value is: \" . $data . PHP_EOL;\n        }, \n        function(FailedCommandException $e) {\n            echo \"Key not found\" . PHP_EOL;\n        });\n```\n\n\n### Decrement\nDecrement value associated with key in Memcached, item **must** exist, decrement command will not create it\nIf you try to decrement a value bellow 0, value will stay at 0. If key is not found, the promise \nwill be rejected with `FailedCommandException`:\n\n```php\n$client\n    -\u003edecr('var', 2)\n    -\u003ethen(\n        function($data){\n            echo \"New value is: \" . $data . PHP_EOL;\n        },\n        function(FailedCommandException $e) {\n            echo \"Key not found\" . PHP_EOL;\n        });\n```\n\nIf value not found, the promise will be rejected with `FailedCommandException`.\n\n## Touch Command\nThe *touch* command is used to update the expiration time of an existing item without fetching it. If the key doesn't \n exist or has been deleted the promise rejects with `FailedCommandException`:\n\n```php\n$client\n    -\u003etouch('var', $exp)\n    -\u003ethen(\n    function($data){\n        echo \"The value was toched\". PHP_EOL;\n    },\n    function(FailedCommandException $e) {\n        echo \"Key not found\" . PHP_EOL;\n    });\n```\n\n## Statistics Command\nThis command can return an array of various stats:\n\n```php\n$client\n    -\u003estats()\n    -\u003ethen(function($result){\n        print_r($result);\n        /*\n        Array\n        (\n            [pid] =\u003e 666\n            [uptime] =\u003e 180660\n            [time] =\u003e 1508342532\n            ... \n            [lru_bumps_dropped] =\u003e 0\n        )\n        */\n    });\n```\n\n## Misc Commands\n### Flush all\nFlush the server key/value pairs (invalidating them) after an optional [\u003ctime\u003e] period:\n\n```php\n$client\n    -\u003eflushAll()\n    -\u003ethen(function() {\n        echo \"Everything was flushed\" . PHP_EOL;\n    });\n```\n\n### Version\nReturn the Memcached server version:\n\n```php\n$client\n    -\u003eversion()\n    -\u003ethen(function($result) {\n        echo \"Memcached version: $result\" . PHP_EOL; // Memcached version: 1.5.0\n     });\n```\n\n### Verbosity\nChange the verbosity output of Memcached server:\n\n```php\n$client\n    -\u003everbosity(2)\n    -\u003ethen(function($result) {\n        echo \"Verbosity was changed to 2\" . PHP_EOL;\n    });\n```\n\n\n## Connection Closing\n\n### End()\nTo close the connection call `end()` method on the client. The client waits till all pending requests are resolved and\nthen closes the connection. All new requests to the client will be rejected with `ConnectionClosedException` exception.\n\n### Close()\nIf you want to force the closing and don't want to wait for pending requests to be resolved, call `close()` method. It \nimmediately closes the connection and rejects all pending requests with `ConnectionClosedException` exception.\n\n## Events Handling\nYou can register event handlers for some client's events.\n\n### close\nWhen the connection to Memcached server is closed, the `close` event is emitted. You can listen to this event to catch\nconnection failures:\n\n```php\n$client-\u003eon('close', function () {\n    // handle closed connection\n});\n```\n\n### error\nWhen an error occurs in the connection, the client emits `error` event and passes an exception \nwith the problem description:\n\n```php\n$client-\u003eon('error', function (Exception $e) {\n    // handle error\n});\n```\n\nFor example you can handle broken connections like this:\n\n```php\n$client-\u003eon('error', function (ConnectionClosedException $e) {\n    // handle broken connection\n});\n```\n\n## Errors Handling\n\nAll exceptions that are thrown by the client or are used to reject the promises extend from the\nbase `seregazhuk\\React\\Memcached\\Exception\\Exception` class.\n\nFor example, if you call an unknown Memcached command the promise will be rejected with `WrongCommandException`:\n\n```php\n$client\n    -\u003eunknown()\n    -\u003ethen('var_dump', function(WrongCommandException $e){\n        echo $e-\u003egetMessage() . PHP_EOL; // Unknown command: unknown\n});\n``` \n\nWhen the connection is broken all pending promises will be rejected with `ConnectionClosedException` exception.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseregazhuk%2Fphp-react-memcached","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseregazhuk%2Fphp-react-memcached","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseregazhuk%2Fphp-react-memcached/lists"}