<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Memcache Functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Referência das Funções" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="m_verifysslcert" HREF="function.m-verifysslcert.html"><LINK REL="NEXT" TITLE="Memcache::add" HREF="function.memcache-add.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.m-verifysslcert.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.memcache-add.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.memcache" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >LXXXVI. Memcache Functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN113885" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="memcache.intro" >Introdução</A ></H1 ><P > Memcache module provides handy procedural and object oriented interface to memcached, highly effective caching daemon, which was especially designed to decrease database load in dynamic web applications. </P ><P > More information about memcached can be found at <A HREF="http://www.danga.com/memcached/" TARGET="_top" >http://www.danga.com/memcached/</A >. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="memcache.requirements" >Dependências</A ></H1 ><P > This module uses functions of <A HREF="http://www.gzip.org/zlib/" TARGET="_top" >zlib</A > to support on-the-fly data compression. Zlib is required to install this module. </P ><P > PHP 4.3.3 or newer is required to use the memcache extension. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="memcache.installation" >Instalação</A ></H1 ><P > Esta estensão <A HREF="http://pecl.php.net" TARGET="_top" >PECL</A > não vem compilada com o PHP. Informações para a instalação desta extensão PECL podem ser encontradas no manual no capitulo entitulado <A HREF="install.pecl.html" >Instalação de extensões PECL</A >. Informações adicionais como novas versões, downloads, arquivos fontes, manutenções, e um Changelog, podem ser obtidos aqui: <A HREF="http://pecl.php.net/package/memcache" TARGET="_top" >http://pecl.php.net/package/memcache</A >. </P ><P > In order to use these functions you must compile PHP with Memcache support by using the <CODE CLASS="option" >--enable-memcache[=DIR]</CODE > option. </P ><P > Windows users will enable <TT CLASS="filename" >php_memcache.dll</TT > inside of <TT CLASS="filename" >php.ini</TT > in order to use these functions. Você pode baixar esta extensão <ACRONYM CLASS="acronym" >PECL</ACRONYM > <ACRONYM CLASS="acronym" >DLL</ACRONYM > a apartir de <A HREF="http://www.php.net/downloads.php" TARGET="_top" > downloads PHP</A > ou em <A HREF="http://snaps.php.net/" TARGET="_top" > http://snaps.php.net/</A >. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="memcache.ini" >Configurações em execução</A ></H1 ><P > O comportamento dessas funções podem ser modificado pelas configurações do <TT CLASS="filename" >php.ini</TT >. </P ><P > <DIV CLASS="table" ><A NAME="AEN113916" ></A ><P ><B >Tabela 1. Memcache Configuration Options</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><COL><THEAD ><TR ><TH >Name</TH ><TH >Default</TH ><TH >Changeable</TH ><TH >Changelog</TH ></TR ></THEAD ><TBODY ><TR ><TD >memcache.allow_failover</TD ><TD >"1"</TD ><TD >PHP_INI_ALL</TD ><TD >Available since Memcache 2.0.2</TD ></TR ><TR ><TD >memcache.max_failover_attempts</TD ><TD >"20"</TD ><TD >PHP_INI_ALL</TD ><TD >Available since Memcache 2.1.0</TD ></TR ><TR ><TD >memcache.chunk_size</TD ><TD >"8192"</TD ><TD >PHP_INI_ALL</TD ><TD >Available since Memcache 2.0.2</TD ></TR ><TR ><TD >memcache.default_port</TD ><TD >"11211"</TD ><TD >PHP_INI_ALL</TD ><TD >Available since Memcache 2.0.2</TD ></TR ></TBODY ></TABLE ></DIV > Para mais detalhes e definições das constantes PHP_INI_*, veja <A HREF="ini.html" >Apêndice H</A >. </P ><P >Breve descrição das diretivas de configuração.</P ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><A NAME="ini.memcache.allow-failover" ></A ><CODE CLASS="parameter" >memcache.allow_failover</CODE > <A HREF="language.types.boolean.html" ><B CLASS="type" >boolean</B ></A ></DT ><DD ><P > Whether to transparently failover to other servers on errors. </P ></DD ><DT ><A NAME="ini.memcache.max-failover-attempts" ></A ><CODE CLASS="parameter" >memcache.max_failover_attempts</CODE > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > Defines how many servers to try when setting and getting data. Used only in conjunction with memcache.allow_failover. </P ></DD ><DT ><A NAME="ini.memcache.chunk-size" ></A ><CODE CLASS="parameter" >memcache.chunk_size</CODE > <A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A ></DT ><DD ><P > Data will be transferred in chunks of this size, setting the value lower requires more network writes. Try increasing this value to 32768 if noticing otherwise inexplicable slowdowns. </P ></DD ><DT ><A NAME="ini.memcache.default-port" ></A ><CODE CLASS="parameter" >memcache.default_port</CODE > <A HREF="language.types.string.html" ><B CLASS="type" >string</B ></A ></DT ><DD ><P > The default TCP port number to use when connecting to the memcached server if no other port is specified. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="memcache.resources" >Tipos Resource</A ></H1 ><P > There is only one resource type used in memcache module - it's the link identifier for a cache server connection. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="memcache.constants" >Constantes pré-definidas</A ></H1 ><DIV CLASS="table" ><A NAME="AEN113979" ></A ><P ><B >Tabela 2. MemCache Constants</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >Name</TH ><TH >Description</TH ></TR ></THEAD ><TBODY ><TR ><TD > <TT CLASS="constant" ><B >MEMCACHE_COMPRESSED</B ></TT > (<A HREF="language.types.integer.html" ><B CLASS="type" >integer</B ></A >) </TD ><TD > Used to turn on-the-fly data compression on with <B CLASS="function" >Memcache::set()</B >, <B CLASS="function" >Memcache::add()</B > e <B CLASS="function" >Memcache::replace()</B >. </TD ></TR ></TBODY ></TABLE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="memcache.examples" >Exemplos</A ></H1 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN113998" ></A ><P ><B >Exemplo 1. memcache extension overview example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />$memcache </font><font color="#007700">= new </font><font color="#0000BB">Memcache</font><font color="#007700">;<br /></font><font color="#0000BB">$memcache</font><font color="#007700">-></font><font color="#0000BB">connect</font><font color="#007700">(</font><font color="#DD0000">'localhost'</font><font color="#007700">, </font><font color="#0000BB">11211</font><font color="#007700">) or die (</font><font color="#DD0000">"Could not connect"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$version </font><font color="#007700">= </font><font color="#0000BB">$memcache</font><font color="#007700">-></font><font color="#0000BB">getVersion</font><font color="#007700">();<br />echo </font><font color="#DD0000">"Server's version: "</font><font color="#007700">.</font><font color="#0000BB">$version</font><font color="#007700">.</font><font color="#DD0000">"<br/>\n"</font><font color="#007700">;<br /><br /></font><font color="#0000BB">$tmp_object </font><font color="#007700">= new </font><font color="#0000BB">stdClass</font><font color="#007700">;<br /></font><font color="#0000BB">$tmp_object</font><font color="#007700">-></font><font color="#0000BB">str_attr </font><font color="#007700">= </font><font color="#DD0000">'test'</font><font color="#007700">;<br /></font><font color="#0000BB">$tmp_object</font><font color="#007700">-></font><font color="#0000BB">int_attr </font><font color="#007700">= </font><font color="#0000BB">123</font><font color="#007700">;<br /><br /></font><font color="#0000BB">$memcache</font><font color="#007700">-></font><font color="#0000BB">set</font><font color="#007700">(</font><font color="#DD0000">'key'</font><font color="#007700">, </font><font color="#0000BB">$tmp_object</font><font color="#007700">, </font><font color="#0000BB">false</font><font color="#007700">, </font><font color="#0000BB">10</font><font color="#007700">) or die (</font><font color="#DD0000">"Failed to save data at the server"</font><font color="#007700">);<br />echo </font><font color="#DD0000">"Store data in the cache (data will expire in 10 seconds)<br/>\n"</font><font color="#007700">;<br /><br /></font><font color="#0000BB">$get_result </font><font color="#007700">= </font><font color="#0000BB">$memcache</font><font color="#007700">-></font><font color="#0000BB">get</font><font color="#007700">(</font><font color="#DD0000">'key'</font><font color="#007700">);<br />echo </font><font color="#DD0000">"Data from the cache:<br/>\n"</font><font color="#007700">;<br /><br /></font><font color="#0000BB">var_dump</font><font color="#007700">(</font><font color="#0000BB">$get_result</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > In the above example, an object is being saved in the cache and then retrieved back. Object and other non-scalar types are serialized before saving, so it's impossible to store resources (i.e. connection identifiers and others) in the cache. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Índice</B ></DT ><DT ><A HREF="function.memcache-add.html" >Memcache::add</A > -- Add an item to the server</DT ><DT ><A HREF="function.memcache-addserver.html" >Memcache::addServer</A > -- Add a memcached server to connection pool</DT ><DT ><A HREF="function.memcache-close.html" >Memcache::close</A > -- Close memcached server connection</DT ><DT ><A HREF="function.memcache-connect.html" >Memcache::connect</A > -- Open memcached server connection</DT ><DT ><A HREF="function.memcache-debug.html" >memcache_debug</A > -- Turn debug output on/off</DT ><DT ><A HREF="function.memcache-decrement.html" >Memcache::decrement</A > -- Decrement item's value</DT ><DT ><A HREF="function.memcache-delete.html" >Memcache::delete</A > -- Delete item from the server</DT ><DT ><A HREF="function.memcache-flush.html" >Memcache::flush</A > -- Flush all existing items at the server</DT ><DT ><A HREF="function.memcache-get.html" >Memcache::get</A > -- Retrieve item from the server</DT ><DT ><A HREF="function.memcache-getextendedstats.html" >Memcache::getExtendedStats</A > -- Get statistics from all servers in pool</DT ><DT ><A HREF="function.memcache-getserverstatus.html" >Memcache::getServerStatus</A > -- Returns server status</DT ><DT ><A HREF="function.memcache-getstats.html" >Memcache::getStats</A > -- Get statistics of the server</DT ><DT ><A HREF="function.memcache-getversion.html" >Memcache::getVersion</A > -- Return version of the server</DT ><DT ><A HREF="function.memcache-increment.html" >Memcache::increment</A > -- Increment item's value</DT ><DT ><A HREF="function.memcache-pconnect.html" >Memcache::pconnect</A > -- Open memcached server persistent connection</DT ><DT ><A HREF="function.memcache-replace.html" >Memcache::replace</A > -- Replace value of the existing item</DT ><DT ><A HREF="function.memcache-set.html" >Memcache::set</A > -- Store data at the server</DT ><DT ><A HREF="function.memcache-setcompressthreshold.html" >Memcache::setCompressThreshold</A > -- Enable automatic compression of large values</DT ><DT ><A HREF="function.memcache-setserverparams.html" >Memcache::setServerParams</A > -- Changes server parameters and status at runtime</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.m-verifysslcert.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.memcache-add.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >m_verifysslcert</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Memcache::add</TD ></TR ></TABLE ></DIV ></BODY ></HTML >