@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * "timeout" in ms, "retry" on node failure 0: no retry (default), 1: retry on set/add/delete, 2: allways retry |
69 | 69 | * "prefix" prefix for keys and "consistent=1" to enable (by default disabled) consistent caching |
70 | 70 | */ |
71 | - function __construct(array $params=null) |
|
71 | + function __construct(array $params = null) |
|
72 | 72 | { |
73 | - $this->params = $params ? $params : array('localhost'); // some reasonable default |
|
73 | + $this->params = $params ? $params : array('localhost'); // some reasonable default |
|
74 | 74 | |
75 | 75 | if (isset($params['timeout'])) |
76 | 76 | { |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $this->consistent = !empty($params['consistent']); |
93 | 93 | } |
94 | 94 | |
95 | - check_load_extension('memcached',true); |
|
95 | + check_load_extension('memcached', true); |
|
96 | 96 | // using a persitent connection for identical $params |
97 | 97 | $this->memcache = new \Memcached(md5(serialize($params))); |
98 | 98 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | $this->memcache->setOption(\Memcached::OPT_SERIALIZER, \Memcached::SERIALIZER_IGBINARY); |
122 | 122 | } |
123 | - elseif(\Memcached::HAVE_JSON) |
|
123 | + elseif (\Memcached::HAVE_JSON) |
|
124 | 124 | { |
125 | 125 | $this->memcache->setOption(\Memcached::OPT_SERIALIZER, \Memcached::SERIALIZER_JSON); |
126 | 126 | } |
@@ -129,18 +129,18 @@ discard block |
||
129 | 129 | if (!count($this->memcache->getServerList())) |
130 | 130 | { |
131 | 131 | $ok = false; |
132 | - foreach($params as $host_port) |
|
132 | + foreach ($params as $host_port) |
|
133 | 133 | { |
134 | - $parts = explode(':',$host_port); |
|
134 | + $parts = explode(':', $host_port); |
|
135 | 135 | $host = array_shift($parts); |
136 | - $port = $parts ? array_shift($parts) : 11211; // default port |
|
136 | + $port = $parts ? array_shift($parts) : 11211; // default port |
|
137 | 137 | |
138 | - $ok = $this->memcache->addServer($host,$port) || $ok; |
|
138 | + $ok = $this->memcache->addServer($host, $port) || $ok; |
|
139 | 139 | //error_log(__METHOD__."(".array2string($params).") memcache->addServer('$host',$port) = ".(int)$ok); |
140 | 140 | } |
141 | 141 | if (!$ok) |
142 | 142 | { |
143 | - throw new Exception (__METHOD__.'('.array2string($params).") Can't open connection to any memcached server!"); |
|
143 | + throw new Exception(__METHOD__.'('.array2string($params).") Can't open connection to any memcached server!"); |
|
144 | 144 | } |
145 | 145 | //error_log(__METHOD__."(".array2string($params).") creating new pool / persitent connection"); |
146 | 146 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @param int $expiration =0 |
156 | 156 | * @return boolean true on success, false on error, incl. key already exists in cache |
157 | 157 | */ |
158 | - function add(array $keys,$data,$expiration=0) |
|
158 | + function add(array $keys, $data, $expiration = 0) |
|
159 | 159 | { |
160 | 160 | return $this->memcache->add(self::key($keys), $data, $expiration) || |
161 | 161 | // if we have multiple nodes, retry on error, but not on data exists |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @param int $expiration =0 |
172 | 172 | * @return boolean true on success, false on error |
173 | 173 | */ |
174 | - function set(array $keys,$data,$expiration=0) |
|
174 | + function set(array $keys, $data, $expiration = 0) |
|
175 | 175 | { |
176 | 176 | return $this->memcache->set(self::key($keys), $data, $expiration) || |
177 | 177 | // if we have multiple nodes, retry on error |
@@ -186,11 +186,11 @@ discard block |
||
186 | 186 | */ |
187 | 187 | function get(array $keys) |
188 | 188 | { |
189 | - if (($data = $this->memcache->get($key=self::key($keys))) === false && |
|
189 | + if (($data = $this->memcache->get($key = self::key($keys))) === false && |
|
190 | 190 | $this->memcache->getResultCode() !== \Memcached::RES_SUCCESS || |
191 | 191 | // if we have multiple nodes, retry on error, but not on not found |
192 | 192 | $this->retry > 1 && $this->memcache->getResultCode() !== \Memcached::RES_NOTFOUND && |
193 | - ($data = $this->memcache->get($key=self::key($keys))) === false && |
|
193 | + ($data = $this->memcache->get($key = self::key($keys))) === false && |
|
194 | 194 | $this->memcache->getResultCode() !== \Memcached::RES_SUCCESS) |
195 | 195 | { |
196 | 196 | //error_log(__METHOD__."(".array2string($keys).") key='$key' NOT found!".' $this->memcache->getResultCode()='.$this->memcache->getResultCode().')'); |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | { |
211 | 211 | $locations = array_pop($keys); |
212 | 212 | $prefix = self::key($keys); |
213 | - foreach($locations as &$location) |
|
213 | + foreach ($locations as &$location) |
|
214 | 214 | { |
215 | 215 | $location = $prefix.'::'.$location; |
216 | 216 | } |
@@ -222,10 +222,10 @@ discard block |
||
222 | 222 | return array(); |
223 | 223 | } |
224 | 224 | $ret = array(); |
225 | - $prefix_len = strlen($prefix)+2; |
|
226 | - foreach($multiple as $location => $data) |
|
225 | + $prefix_len = strlen($prefix) + 2; |
|
226 | + foreach ($multiple as $location => $data) |
|
227 | 227 | { |
228 | - $key = substr($location,$prefix_len); |
|
228 | + $key = substr($location, $prefix_len); |
|
229 | 229 | //error_log(__METHOD__."(".array2string($locations).") key='$key' found ".bytes($data)." bytes)."); |
230 | 230 | $ret[$key] = $data; |
231 | 231 | } |
@@ -253,6 +253,6 @@ discard block |
||
253 | 253 | */ |
254 | 254 | private function key(array $keys) |
255 | 255 | { |
256 | - return implode('::',$keys); |
|
256 | + return implode('::', $keys); |
|
257 | 257 | } |
258 | 258 | } |