Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 9189

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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>Store an item</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="memcached.resetserverlist.html">Memcached::resetServerList</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="memcached.setbykey.html">Memcached::setByKey</a></div>
 <div class="up"><a href="class.memcached.html">Memcached</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="memcached.set" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Memcached::set</h1>
  <p class="verinfo">(PECL memcached &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">Memcached::set</span> &mdash; <span class="dc-title">Store an item</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-memcached.set-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>Memcached::set</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$key</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$expiration</code></span>
  ] )</div>

  <p class="para rdfs-comment">
    <span class="function"><strong>Memcached::set()</strong></span> stores the <em><code class="parameter">value</code></em>
   on a memcache server under the specified <em><code class="parameter">key</code></em>. The
   <em><code class="parameter">expiration</code></em> parameter can be used to control when the
   value is considered expired.
  </p>
  <p class="para">
   The value can be any valid PHP type except for resources, because those
   cannot be represented in a serialized form. If the
   <strong><code>Memcached::OPT_COMPRESSION</code></strong> option is turned on, the
   serialized value will also be compressed before storage.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-memcached.set-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 under which to store the value.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">value</code></em></span>
     <dd>

      <p class="para">
       The value to store.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">expiration</code></em></span>
     <dd>

      <p class="para">
       The expiration time, defaults to 0. See <a href="memcached.expiration.html" class="link">Expiration Times</a> for more info.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-memcached.set-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure.
   Use  <span class="methodname"><a href="memcached.getresultcode.html" class="methodname">Memcached::getResultCode()</a></span> if necessary.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-memcached.set-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-4452">
    <p><strong>Example #1  <span class="function"><strong>Memcached::set()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServer</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'int'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">99</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'string'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'a&nbsp;simple&nbsp;string'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'array'</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">11</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">12</span><span style="color: #007700">));<br /></span><span style="color: #FF8000">/*&nbsp;expire&nbsp;'object'&nbsp;key&nbsp;in&nbsp;5&nbsp;minutes&nbsp;*/<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'object'</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">stdclass</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">()&nbsp;+&nbsp;</span><span style="color: #0000BB">300</span><span style="color: #007700">);<br /><br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'int'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'string'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'array'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'object'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
int(99)
string(15) &quot;a simple string&quot;
array(2) {
  [0]=&gt;
  int(11)
  [1]=&gt;
  int(12)
}
object(stdClass)#1 (0) {
}
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-memcached.set-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="methodname"><a href="memcached.setbykey.html" class="methodname" rel="rdfs-seeAlso">Memcached::setByKey()</a> - Store an item on a specific server</span></li>
    <li class="member"> <span class="methodname"><a href="memcached.add.html" class="methodname" rel="rdfs-seeAlso">Memcached::add()</a> - Add an item under a new key</span></li>
    <li class="member"> <span class="methodname"><a href="memcached.replace.html" class="methodname" rel="rdfs-seeAlso">Memcached::replace()</a> - Replace the item under an existing key</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="memcached.resetserverlist.html">Memcached::resetServerList</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="memcached.setbykey.html">Memcached::setByKey</a></div>
 <div class="up"><a href="class.memcached.html">Memcached</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>