IMPRESS dotted_line CONTACT dotted_line search dotted_line Kontakt dotted_line sitemap dotted_line print
142 PHP-Resource users online

Switch to another languags Deutsch aktuelle Sprache Englisch

PHP Manual


(PECL memcached >= 0.1.0)

Memcached::getMultiRetrieve multiple items


public mixed Memcached::getMulti ( array $keys [, array &$cas_tokens [, int $flags ]] )

Memcached::getMulti() is similar to Memcached::get(), but instead of a single key item, it retrieves multiple items the keys of which are specified in the keys array. If cas_tokens variable is provided, it is filled with the CAS token values for the found items.


Unlike Memcached::get() it is not possible to specify a read-through cache callback for Memcached::getMulti(), because the memcache protocol does not provide information on which keys were not found in the multi-key request.

The flags parameter can be used to specify additional options for Memcached::getMulti(). Currently, the only available option is Memcached::GET_PRESERVE_ORDER that ensures that the keys are returned in the same order as they were requested in.



Array of keys to retrieve.


The variable to store the CAS tokens for the found items.


The flags for the get operation.

Return Values

Returns the array of found items or FALSE on failure. Use Memcached::getResultCode() if necessary.


Example #1 Memcached::getMulti() example

= new Memcached();

$items = array(
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3'
$result $m->getMulti(array('key1''key3''badkey'), $cas);

The above example will output something similar to:

array(2) {
  string(6) "value1"
  string(6) "value3"
array(2) {

Example #2 Memcached::GET_PRESERVE_ORDER example

= new Memcached();

$data = array(
'foo' => 'foo-data',
'bar' => 'bar-data',
'baz' => 'baz-data',
'lol' => 'lol-data',
'kek' => 'kek-data',


$null null;
$keys array_keys($data);
$keys[] = 'zoo';
$got $m->getMulti($keys$nullMemcached::GET_PRESERVE_ORDER);

foreach (
$got as $k => $v) {
"$k $v\n";

The above example will output something similar to:

foo foo-data
bar bar-data
baz baz-data
lol lol-data
kek kek-data

See Also

Comments to the PHP manual
Write new comment


New Tutorial entries

Migration einer PHP 5 App auf PHP 7

Dieses PHP 7 Tutorial zeigt dir, wie du dein PHP5 Script auf PHP7 umstellst.

Berni | Category: PHP
PHP 7 Virtual Machine

Dieser Artikel zielt darauf ab, einen Überblick über die Zend Virtual Machine, wie es in PHP 7 gefunden wird.

Berni | Category: PHP
plotting masters - a professional guide - Teil II

Grafische Interpolation und Bestapproximation von numerischen Wertepaaren: Wir wollen Punkte auf einer Zeichenebene über verschiedene Verfahren miteinander verbinden.

EVAMasters | Category: PHP