1
0
mirror of https://github.com/php/doc-ru.git synced 2026-03-24 07:42:22 +01:00
Files
archived-doc-ru/reference/shmop/examples.xml
2026-01-26 15:34:34 +00:00

69 lines
2.5 KiB
XML
Raw Permalink 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: 6ce09e40979a5cd7ee87a4799cbaf1d8d17a3dc1 Maintainer: aur Status: ready -->
<!-- Reviewed: no -->
<chapter xmlns="http://docbook.org/ns/docbook" xml:id="shmop.examples">
&reftitle.examples;
<section xml:id="shmop.examples-basic">
<title>Базовое использование</title>
<example>
<title>Обзор операций с разделяемой памятью</title>
<programlisting role="php">
<![CDATA[
<?php
// Создание блока с идентификатором 0xff3 и размером в 100 байт.
$shm_id = shmop_open(0xff3, "c", 0644, 100);
if (!$shm_id) {
echo "Невозможно зарезервировать блок в сегменте памяти\n";
}
// Получение размера блока в разделяемой памяти
$shm_size = shmop_size($shm_id);
echo "Участок памяти, размером: " . $shm_size . ", успешно зарезервирован.\n";
// Проверочная запись некоторой строки в разделяемую память
$shm_bytes_written = shmop_write($shm_id, "Мой маленький блок", 0);
if ($shm_bytes_written != strlen("Мой маленький блок")) {
echo "Не удалось записать весь размер данных\n";
}
// Получение хранимой строки из разделяемой памяти
$my_string = shmop_read($shm_id, 0, $shm_size);
if (!$my_string) {
echo "Невозможно прочитать данные из блока памяти\n";
}
echo "Данные, размещённые в разделяемой памяти: " . $my_string . "\n";
// Удаление блока и закрытие сегмента разделяемой памяти
if (!shmop_delete($shm_id)) {
echo "Невозможно отметить участок памяти для освобождения.";
}
shmop_close($shm_id);
?>
]]>
</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
-->