Files
doc-fr/reference/memcached/callbacks.xml
Yannick Torres 9df3faab22 Sync with EN
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@350799 c90b9560-bf6c-de11-be94-00142212c4b1
2020-10-06 15:59:49 +00:00

126 lines
3.3 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 80872147aa52367137bd3d168412f70cbe2ddf9c Maintainer: yannick Status: ready -->
<!-- Reviewed: no -->
<chapter xml:id="memcached.callbacks" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Fonctions de rappel</title>
<section xml:id="memcached.callbacks.result">
<title>Fonctions de rappel de résultats</title>
<para>
Les fonctions de rappel de résultats (type <type>callable</type>)
sont appelées par les fonctions
<methodname>Memcached::getDelayed</methodname> ou
<methodname>Memcached::getDelayedBykey</methodname>, pour chaque
élément du jeu de résultat. Les fonctions de rappel reçoivent un objet
Memcached et un tableau avec les informations sur l'élément. La fonction
de rappel n'a pas besoin de retourner quoi que ce soit.
</para>
<example>
<title>Exemple de fonction de rappel de résultats</title>
<programlisting role="php">
<![CDATA[
<?php
$m = new Memcached();
$m->addServer('localhost', 11211);
$items = array(
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3'
);
$m->setMulti($items);
$m->getDelayed(array('key1', 'key3'), true, 'result_cb');
function result_cb($memc, $item)
{
var_dump($item);
}
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
array(3) {
["key"]=>
string(4) "key1"
["value"]=>
string(6) "value1"
["cas"]=>
float(49)
}
array(3) {
["key"]=>
string(4) "key3"
["value"]=>
string(6) "value3"
["cas"]=>
float(50)
}
]]>
</screen>
</example>
</section>
<section xml:id="memcached.callbacks.read-through">
<title>Fonctions de rappel sur clé absente</title>
<para>
Les fonctions de rappel sur clé absente sont appelées quand un élément ne peut
pas être lu sur le serveur. La fonction de rappel reçoit un objet Memcached,
la clé demandée, et une valeur de variable par référence. La fonction de rappel
est alors responsable d'affecter la valeur, puis de retourner
&true; ou &false;. Si la fonction de rappel retourne &true;
Memcached va stocker la valeur ainsi créée dans le serveur, et la retourner
à la fonction appelante. Seules <methodname>Memcached::get</methodname> et
<methodname>Memcached::getByKey</methodname> supportent ces fonctions,
car le protocole memcache ne fournit aucune information sur l'absence de
clé dans une requête multiclé.
</para>
<example>
<title>Fonctions de rappel sur clé absente</title>
<programlisting role="php">
<![CDATA[
<?php
$m = new Memcached();
$m->addServer('localhost', 11211);
$profile_info = $m->get('user:'.$user_id, 'user_info_cb');
function user_info_cb($memc, $key, &$value)
{
$user_id = substr($key, 5);
/* Lit un profil dans une base de données */
/* ... */
$value = $profile_info;
return true;
}
?>
]]>
</programlisting>
</example>
</section>
</chapter>
<!-- 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
-->