<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Retrieve item from the server</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="memcache.flush.html">Memcache::flush</a></div> <div class="next" style="text-align: right; float: right;"><a href="memcache.getextendedstats.html">Memcache::getExtendedStats</a></div> <div class="up"><a href="class.memcache.html">Memcache</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="memcache.get" class="refentry"> <div class="refnamediv"> <h1 class="refname">Memcache::get</h1> <p class="verinfo">(PECL memcache >= 0.2.0)</p><p class="refpurpose"><span class="refname">Memcache::get</span> — <span class="dc-title">Retrieve item from the server</span></p> </div> <div class="refsect1 description" id="refsect1-memcache.get-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>Memcache::get</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$key</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$flags</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><strong>Memcache::get</strong></span> ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$keys</code></span> [, <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$flags</code></span> ] )</div> <p class="para rdfs-comment"> <span class="function"><strong>Memcache::get()</strong></span> returns previously stored data if an item with such <em><code class="parameter">key</code></em> exists on the server at this moment. </p> <p class="para"> You can pass array of keys to <span class="function"><strong>Memcache::get()</strong></span> to get array of values. The result array will contain only found key-value pairs. </p> </div> <div class="refsect1 parameters" id="refsect1-memcache.get-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">key</code></em></span> <dd> <p class="para"> The key or array of keys to fetch. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">flags</code></em></span> <dd> <p class="para"> If present, flags fetched along with the values will be written to this parameter. These flags are the same as the ones given to for example <span class="function"><a href="memcache.set.html" class="function">Memcache::set()</a></span>. The lowest byte of the int is reserved for pecl/memcache internal usage (e.g. to indicate compression and serialization status). </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-memcache.get-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the string associated with the <em><code class="parameter">key</code></em> or an array of found key-value pairs when <em><code class="parameter">key</code></em> is an <span class="type"><a href="language.types.array.html" class="type array">array</a></span>. Returns <strong><code>FALSE</code></strong> on failure, <em><code class="parameter">key</code></em> is not found or <em><code class="parameter">key</code></em> is an empty <span class="type"><a href="language.types.array.html" class="type array">array</a></span>. </p> </div> <div class="refsect1 examples" id="refsect1-memcache.get-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4415"> <p><strong>Example #1 <span class="function"><strong>Memcache::get()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">/* procedural API */<br /></span><span style="color: #0000BB">$memcache_obj </span><span style="color: #007700">= </span><span style="color: #0000BB">memcache_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$var </span><span style="color: #007700">= </span><span style="color: #0000BB">memcache_get</span><span style="color: #007700">(</span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">, </span><span style="color: #DD0000">'some_key'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* OO API */<br /></span><span style="color: #0000BB">$memcache_obj </span><span style="color: #007700">= new </span><span style="color: #0000BB">Memcache</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">-></span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$var </span><span style="color: #007700">= </span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">-></span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'some_key'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* <br />You also can use array of keys as a parameter.<br />If such item wasn't found at the server, the result<br />array simply will not include such key.<br />*/<br /><br />/* procedural API */<br /></span><span style="color: #0000BB">$memcache_obj </span><span style="color: #007700">= </span><span style="color: #0000BB">memcache_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$var </span><span style="color: #007700">= </span><span style="color: #0000BB">memcache_get</span><span style="color: #007700">(</span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">, Array(</span><span style="color: #DD0000">'some_key'</span><span style="color: #007700">, </span><span style="color: #DD0000">'another_key'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/* OO API */<br /></span><span style="color: #0000BB">$memcache_obj </span><span style="color: #007700">= new </span><span style="color: #0000BB">Memcache</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">-></span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">, </span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$var </span><span style="color: #007700">= </span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">-></span><span style="color: #0000BB">get</span><span style="color: #007700">(Array(</span><span style="color: #DD0000">'some_key'</span><span style="color: #007700">, </span><span style="color: #DD0000">'second_key'</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="memcache.flush.html">Memcache::flush</a></div> <div class="next" style="text-align: right; float: right;"><a href="memcache.getextendedstats.html">Memcache::getExtendedStats</a></div> <div class="up"><a href="class.memcache.html">Memcache</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>