<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="memcached.getmulti" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>Memcached::getMulti</refname>
  <refpurpose>Retrieve multiple items</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis role="Memcached">
   <modifier>public</modifier> <type class="union"><type>array</type><type>false</type></type><methodname>Memcached::getMulti</methodname>
   <methodparam><type>array</type><parameter>keys</parameter></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>get_flags</parameter><initializer>0</initializer></methodparam>
  </methodsynopsis>
  <para>
   <function>Memcached::getMulti</function> is similar to
   <methodname>Memcached::get</methodname>, but instead of a single key
   item, it retrieves multiple items the keys of which are specified in the
   <parameter>keys</parameter> array.
   <note>
    <para>
     Before v3.0 a second argument <parameter role="reference">cas_tokens</parameter> was in use.
     It was filled with the CAS token values for the found items.
     The <parameter role="reference">cas_tokens</parameter> parameter was removed in v3.0 of the extension.
     It was replaced with a new flag <constant>Memcached::GET_EXTENDED</constant>
     that needs is to be used as the value for <parameter>get_flags</parameter>.
    </para>
   </note>
  </para>
  <para>
   The <parameter>get_flags</parameter> parameter can be used to specify
   additional options for <function>Memcached::getMulti</function>.
   <constant>Memcached::GET_PRESERVE_ORDER</constant> ensures that the
   keys are returned in the same order as they were requested in.
   <constant>Memcached::GET_EXTENDED</constant> ensures that the
   CAS tokens will be fetched too.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>keys</parameter></term>
     <listitem>
      <para>
       Array of keys to retrieve.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>get_flags</parameter></term>
     <listitem>
      <para>
       The flags for the get operation.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns the array of found items&return.falseforfailure;.
   &memcached.result.getresultcode;
  </para>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <informaltable>
   <tgroup cols="2">
    <thead>
     <row>
      <entry>&Version;</entry>
      <entry>&Description;</entry>
     </row>
    </thead>
    <tbody>
     <row>
      <entry>PECL memcached 3.0.0</entry>
      <entry>
       The <parameter role="reference">cas_tokens</parameter> parameter was removed.
       The <constant>Memcached::GET_EXTENDED</constant> was added and when passed as a flag it ensures the CAS tokens to be fetched.
      </entry>
     </row>
    </tbody>
   </tgroup>
  </informaltable>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>Memcached::getMulti</function> example for Memcached v3</title>
    <programlisting role="php">
<![CDATA[
<?php
// Valid for v3 of the extension

$m = new Memcached();
$m->addServer('localhost', 11211);

$items = array(
    'key1' => 'value1',
    'key2' => 'value2',
    'key3' => 'value3'
);
$m->setMulti($items);
$result = $m->getMulti(array('key1', 'key3', 'badkey'));
var_dump($result);
?>
]]>
    </programlisting>
    &example.outputs.similar;
    <screen>
<![CDATA[
array(2) {
  ["key1"]=>
  string(6) "value1"
  ["key3"]=>
  string(6) "value3"
}
]]>
    </screen>
   </example>
  </para>

  <para>
   <example>
    <title><function>Memcached::getMulti</function> example for Memcached v1 and v2</title>
    <programlisting role="php">
<![CDATA[
<?php
// Valid for v1 and v2 of the extension

$m = new Memcached();
$m->addServer('localhost', 11211);

$items = array(
    'key1' => 'value1',
    'key2' => 'value2',
    'key3' => 'value3'
);
$m->setMulti($items);
$result = $m->getMulti(array('key1', 'key3', 'badkey'), $cas);
var_dump($result, $cas);
?>
]]>
    </programlisting>
    &example.outputs.similar;
    <screen>
<![CDATA[
array(2) {
  ["key1"]=>
  string(6) "value1"
  ["key3"]=>
  string(6) "value3"
}
array(2) {
  ["key1"]=>
  float(2360)
  ["key3"]=>
  float(2362)
}
]]>
    </screen>
   </example>
  </para>

  <para>
   <example>
    <title><constant>Memcached::GET_PRESERVE_ORDER</constant> example for Memcached v3</title>
    <programlisting role="php">
<![CDATA[
<?php
// Valid for v3 of the extension

$m = new Memcached();
$m->addServer('localhost', 11211);

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

$m->setMulti($data, 3600);

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

foreach ($got as $k => $v) {
    echo "$k $v\n";
}
?>
]]>
    </programlisting>
    &example.outputs.similar;
    <screen>
<![CDATA[
foo foo-data
bar bar-data
baz baz-data
lol lol-data
kek kek-data
zoo 
]]>
    </screen>
   </example>
  </para>

  <para>
   <example>
    <title><constant>Memcached::GET_PRESERVE_ORDER</constant> example for Memcached v1 and v2</title>
    <programlisting role="php">
<![CDATA[
<?php
// Valid for v1 and v2 of the extension

$m = new Memcached();
$m->addServer('localhost', 11211);

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

$m->setMulti($data, 3600);

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

foreach ($got as $k => $v) {
    echo "$k $v\n";
}
?>
]]>
    </programlisting>
    &example.outputs.similar;
    <screen>
<![CDATA[
foo foo-data
bar bar-data
baz baz-data
lol lol-data
kek kek-data
zoo 
]]>
    </screen>
   </example>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><methodname>Memcached::getMultiByKey</methodname></member>
    <member><methodname>Memcached::get</methodname></member>
    <member><methodname>Memcached::getDelayed</methodname></member>
   </simplelist>
  </para>
 </refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
