<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.memcache.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'memcache.set.php',
    1 => 'Memcache::set',
    2 => 'Store data at the server',
  ),
  'up' => 
  array (
    0 => 'class.memcache.php',
    1 => 'Memcache',
  ),
  'prev' => 
  array (
    0 => 'memcache.replace.php',
    1 => 'Memcache::replace',
  ),
  'next' => 
  array (
    0 => 'memcache.setcompressthreshold.php',
    1 => 'Memcache::setCompressThreshold',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/memcache/memcache/set.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="memcache.set" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Memcache::set</h1>
  <h1 class="refname">memcache_set</h1>
  <p class="verinfo">(PECL memcache &gt;= 0.2.0)</p><p class="refpurpose"><span class="refname">Memcache::set</span> -- <span class="refname">memcache_set</span> &mdash; <span class="dc-title">Store data at the server</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-memcache.set-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>Memcache::set</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$key</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$var</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flag</code><span class="initializer"> = ?</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$expire</code><span class="initializer"> = ?</span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <div class="methodsynopsis dc-description"><span class="methodname"><strong>memcache_set</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.memcache.php" class="type Memcache">Memcache</a></span> <code class="parameter">$memcache</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$key</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$var</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flag</code><span class="initializer"> = ?</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$expire</code><span class="initializer"> = ?</span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>


  <p class="para rdfs-comment">
   <span class="function"><strong>Memcache::set()</strong></span> stores an item
   <code class="parameter">var</code> with <code class="parameter">key</code> on the
   memcached server. Parameter <code class="parameter">expire</code> is expiration
   time in seconds. If it&#039;s 0, the item never expires (but memcached server
   doesn&#039;t guarantee this item to be stored all the time, it could be deleted
   from the cache to make place for other items).
   You can use <strong><code><a href="memcache.constants.php#constant.memcache-compressed">MEMCACHE_COMPRESSED</a></code></strong> constant as
   <code class="parameter">flag</code> value if you want to use on-the-fly
   compression (uses zlib).
   <blockquote class="note"><p><strong class="note">Nota</strong>: 
    <span class="simpara">
     Remember that resource variables (i.e. file and connection descriptors)
     cannot be stored in the cache, because they cannot be adequately
     represented in serialized state.
    </span>
   </p></blockquote>
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-memcache.set-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">key</code></dt>
    <dd>
     <span class="simpara">
      The key that will be associated with the item.
     </span>
    </dd>
   
   
    <dt><code class="parameter">var</code></dt>
    <dd>
     <span class="simpara">
      The variable to store. Strings and integers are stored as is, other
      types are stored serialized.
     </span>
    </dd>
   
   
    <dt><code class="parameter">flag</code></dt>
    <dd>
     <span class="simpara">
      Use <strong><code><a href="memcache.constants.php#constant.memcache-compressed">MEMCACHE_COMPRESSED</a></code></strong> to store the item
      compressed (uses zlib).
     </span>
    </dd>
   
   
    <dt><code class="parameter">expire</code></dt>
    <dd>
     <span class="simpara">
      Expiration time of the item. If it&#039;s equal to zero, the item will never
      expire. You can also use Unix timestamp or a number of seconds starting
      from current time, but in the latter case the number of seconds may not
      exceed 2592000 (30 days).
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-memcache.set-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="simpara">
   Restituisce <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> in caso di successo, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> in caso di fallimento.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-memcache.set-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>Memcache::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 /></span><span style="color: #FF8000">/* procedural API */<br /><br />/* connect to memcached server */<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 /><br /></span><span style="color: #FF8000">/*<br />set value of item with key 'var_key'<br />using 0 as flag value, compression is not used<br />expire time is 30 seconds<br />*/<br /></span><span style="color: #0000BB">memcache_set</span><span style="color: #007700">(</span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">, </span><span style="color: #DD0000">'var_key'</span><span style="color: #007700">, </span><span style="color: #DD0000">'some variable'</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">30</span><span style="color: #007700">);<br /><br />echo </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">'var_key'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   <div class="example" id="example-2">
    <p><strong>Example #2 <span class="function"><strong>Memcache::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 /></span><span style="color: #FF8000">/* OO API */<br /><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 /><br /></span><span style="color: #FF8000">/* connect to memcached server */<br /></span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">-&gt;</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 /><br /></span><span style="color: #FF8000">/*<br />set value of item with key 'var_key', using on-the-fly compression<br />expire time is 50 seconds<br />*/<br /></span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'var_key'</span><span style="color: #007700">, </span><span style="color: #DD0000">'some really big variable'</span><span style="color: #007700">, </span><span style="color: #0000BB">MEMCACHE_COMPRESSED</span><span style="color: #007700">, </span><span style="color: #0000BB">50</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'var_key'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-memcache.set-seealso">
  <h3 class="title">Vedere anche:</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="memcache.add.php" class="function" rel="rdfs-seeAlso">Memcache::add()</a> - Add an item to the server</span></li>
   <li><span class="function"><a href="memcache.replace.php" class="function" rel="rdfs-seeAlso">Memcache::replace()</a> - Replace value of the existing item</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>