1This is an official repository for pecl-memcache plugin since 2019.
2
3This repository contains modified pecl-memcache plugin ported to PHP8,
4which was originally developed for the need of hosting company in Slovakia (Websupport.sk).
5
6The latest release is 8.0 (released: 2020-12-06) with support for PHP 8.0.
7
8Please use version 4.0.5.1 (released: 2020-12-19) for PHP 7.x from branch NON_BLOCKING_IO_php7.
9
10See: https://github.com/websupport-sk/pecl-memcache/releases
11See also release on PECL: https://pecl.php.net/package/memcache
12
13Feel free to use it and post patches.
14
15
16
17Original README:
18
19memcached module for PHP
20------------------------
21This module requires zlib library, used for on-the-fly data (de)compression.
22Also, you'll need memcached to use it =)
23
24The memcached website is here:
25 http://www.danga.com/memcached/
26
27You will probably need libevent to install memcached:
28You can download it here: http://www.monkey.org/~provos/libevent/
29
30How to run tests:
311. sh tests/memcache.sh
322. TEST_PHP_EXECUTABLE=/usr/local/bin/php php -dextension=modules/memcache.so run-tests.php -d extension=modules/memcache.so
33
34
35New API in 3.0
36------------------------
37
38 Version 3 introduces a new class "MemcachePool" which implements the new API, the
39 old class "Memcache" is still retained (but is deprecated) with the same interface
40 for backwards compatibility. Please note that you need a new memcached version to
41 use the CAS, default value to increment/decrement, append and prepend, and binary
42 protocol features.
43
44 New INI directives are available to allow control over protocol, redundancy and hash
45 strategy selection. These are
46
47 # The binary protocol results in less traffic and is more efficient
48 # for the client and server to generate/parse
49
50 memcache.protocol = {ascii, binary} # default ascii
51
52 # When enabled the client sends requests to N servers in parallel, resulting in
53 # a somewhat crude reduncancy or mirroring, suitable when used as a session
54 # storage.
55 #
56 # If data integrity is of greater importance a real replicating memcached
57 # backend such as "repcached" (http://sourceforge.net/projects/repcached/) is
58 # recommended
59
60 memcache.redundancy = <int> # default 1
61 memcache.session_redundancy = <int> # default 2
62
63 # Hash strategy and function selection. The consistent hashing strategy
64 # is now the default as it allows servers to be added and removed from
65 # the pool without resulting in all or most keys being re-mapped to
66 # other server (ie. voiding the cache)
67
68 memcache.hash_strategy = {standard, consistent} # default consistent
69 memcache.hash_function = {crc32, fnv} # default crc32
70
71 # Compression is enabled by default, the threshold which control the minimum
72 # string length which triggers compresssion can be changed as
73
74 memcache.compress_threshold = <int> # default 20000
75
76
77 The directives are used by the MemcachePool constructor so you can instantiate
78 several pools with different settings by using ini_set() creativly. For example
79
80 ini_set('memcache.protocol', 'binary');
81
82 $binarypool = new MemcachePool();
83 $binarypool->addServer(...)
84
85 ini_set('memcache.protocol', 'ascii');
86 ini_set('memcache.redundancy', '2');
87
88 $redundantpool = new MemcachePool();
89 $redundantpool->addServer(...)
90
91 ini_set('memcache.redundancy', '1');
92
93
94 The new interface looks like
95
96class MemcachePool() {
97 bool connect(string host, int tcp_port = 11211, int udp_port = 0, bool persistent = true, int weight = 1, int timeout = 1, int retry_interval = 15)
98 bool addServer(string host, int tcp_port = 11211, int udp_port = 0, bool persistent = true, int weight = 1, int timeout = 1, int retry_interval = 15, bool status = true)
99 bool setServerParams(string host, int tcp_port = 11211, int timeout = 1, int retry_interval = 15, bool status = true)
100
101 /**
102 * Supports fetching flags and CAS values
103 */
104 mixed get(mixed key, mixed &flags = null, mixed &cas = null)
105
106 /**
107 * Supports multi-set, for example
108 * $memcache->set(array('key1' => 'val1', 'key2' => 'val1'), null, 0, 60)
109 */
110 bool add(mixed key, mixed var = null, int flag = 0, int exptime = 0)
111 bool set(mixed key, mixed var = null, int flag = 0, int exptime = 0)
112 bool replace(mixed key, mixed var = null, int flag = 0, int exptime = 0)
113
114 /**
115 * Compare-and-Swap, uses the CAS param from MemcachePool::get()
116 */
117 bool cas(mixed key, mixed var = null, int flag = 0, int exptime = 0, int cas = 0)
118
119 /**
120 * Prepends/appends a value to an existing one
121 */
122 bool append(mixed key, mixed var = null, int flag = 0, int exptime = 0)
123 bool prepend(mixed key, mixed var = null, int flag = 0, int exptime = 0)
124
125 /**
126 * Supports multi-key operations, for example
127 * $memcache->delete(array('key1', 'key2'))
128 */
129 bool delete(mixed key, int exptime = 0)
130
131 /**
132 * Supports multi-key operations, for example
133 * $memcache->increment(array('key1', 'key2'), 1, 0, 0)
134 *
135 * The new defval (default value) and exptime (expiration time) are used
136 * if the key doesn't already exist. They must be supplied (even if 0) for
137 * this to be enabled.
138 *
139 * Returns an integer with the new value if key is a string
140 * Returns an array of integers if the key is an array
141 */
142 mixed increment(mixed key, int value = 1, int defval = 0, int exptime = 0)
143 mixed decrement(mixed key, int value = 1, int defval = 0, int exptime = 0)
144
145 /**
146 * Assigns a pool-specific failure callback which will be called when
147 * a request fails. May be null in order to disable callbacks. The callback
148 * receive arguments like
149 *
150 * function mycallback($host, $tcp_port, $udp_port, $error, $errnum)
151 *
152 * Where $host and $error are strings or null, the other params are integers.
153 */
154 bool setFailureCallback(function callback)
155
156 /**
157 * Locates the server a given would be hashed to
158 *
159 * Returns a string "hostname:port" on success
160 * Returns false on failure such as invalid key
161 */
162 string findServer(string key)
163}
164
165
166Maintainers:
167Herman J. Radtke III hradtke at php dot net
168