1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-25 16:22:18 +01:00
Files
archived-doc-ru/reference/memcache/examples.xml
Sergey Panteleev daef8df962 Обнуление тега Reviewed (#364)
[skip-lint]
[skip-spellcheck]
2021-11-16 13:03:53 +03:00

83 lines
2.6 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 79dcbe011fb254dcd92c597064571fe313362a09 Maintainer: mch Status: ready -->
<!-- Reviewed: no -->
<chapter xml:id="memcache.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<section xml:id="memcache.examples-overview">
<title>Базовое использование</title>
<para>
<example>
<title>Пример использования модуля memcache</title>
<para>
В этом примере происходит сохранение объекта в кеше и его последующее
чтение. Объекты и другие нескалярные типы сериализируются перед сохранением,
что делает невозможным хранение ресурсов (например, идентификаторов
подключений и др.) в кеше.
</para>
<programlisting role="php">
<![CDATA[
<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Не могу подключиться");
$version = $memcache->getVersion();
echo "Версия сервера: ".$version."<br/>\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;
$memcache->set('key', $tmp_object, false, 10) or die ("Ошибка при сохранении данных на сервере");
echo "Данные сохранены в кеше. (время жизни данных 10 секунд)<br/>\n";
$get_result = $memcache->get('key');
echo "Данные из кеша:<br/>\n";
var_dump($get_result);
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Использование memcache в качестве обработчика сессий</title>
<programlisting role="php">
<![CDATA[
<?php
$session_save_path = "tcp://$host:$port?persistent=1&weight=2&timeout=2&retry_interval=10, ,tcp://$host:$port ";
ini_set('session.save_handler', 'memcache');
ini_set('session.save_path', $session_save_path);
?>
]]>
</programlisting>
</example>
</para>
</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
-->