php-doc-en/functions/shmop.xml
Hartmut Holzgraefe 7839d91186 added DO NOT EDIT noctice to old english functions files,
removing the others


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@78562 c90b9560-bf6c-de11-be94-00142212c4b1
2002-04-17 19:58:46 +00:00

377 lines
12 KiB
XML
Executable file

<!-- D O N O T E D I T T H I S F I L E ! ! !
it is still here for historical reasons only
(as translators may need to check old revision diffs)
if you want to change things documented in this file
you should now edit the files found under en/reference
instead -->
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.16 $ -->
<reference id="ref.shmop">
<title>Shared Memory Functions</title>
<titleabbrev>shmop</titleabbrev>
<partintro>
<para>
Shmop is an easy to use set of functions that allows php to read,
write, create and delete UNIX shared memory segments. The functions
will not work on windows, as it does not support shared memory. To
use shmop you will need to compile php with the --enable-shmop parameter
in your configure line.
</para>
<note>
<simpara>
This module is experimental. API and others are subject to be
changed without notice.
</simpara>
<simpara>
In PHP 4.0.3, there functions were prefixed by <literal>shm</literal>
rather than <literal>shmop</literal>.
<!-- TODO: do the old shm_* funcs still work, i.e. are they still
aliased? -->
</simpara>
</note>
<para>
<example>
<title>Shared Memory Operations Overview</title>
<programlisting role="php">
<![CDATA[
<?php
// Create 100 byte shared memory block with system id if 0xff3
$shm_id = shmop_open(0xff3, "c", 0644, 100);
if(!$shm_id) {
echo "Couldn't create shared memory segment\n";
}
// Get shared memory block's size
$shm_size = shmop_size($shm_id);
echo "SHM Block Size: ".$shm_size. " has been created.\n";
// Lets write a test string into shared memory
$shm_bytes_written = shmop_write($shm_id, "my shared memory block", 0);
if($shm_bytes_written != strlen("my shared memory block")) {
echo "Couldn't write the entire length of data\n";
}
// Now lets read the string back
$my_string = shmop_read($shm_id, 0, $shm_size);
if(!$my_string) {
echo "Couldn't read from shared memory block\n";
}
echo "The data inside shared memory was: ".$my_string."\n";
//Now lets delete the block and close the shared memory segment
if(!shmop_delete($shm_id)) {
echo "Couldn't mark shared memory block for deletion.";
}
shmop_close($shm_id);
?>
]]>
</programlisting>
</example>
</para>
</partintro>
<refentry id="function.shmop-open">
<refnamediv>
<refname>shmop_open</refname>
<refpurpose>Create or open shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>shmop_open</methodname>
<methodparam><type>int</type><parameter>key</parameter></methodparam>
<methodparam><type>string</type><parameter>flags</parameter></methodparam>
<methodparam><type>int</type><parameter>mode</parameter></methodparam>
<methodparam><type>int</type><parameter>size</parameter></methodparam>
</methodsynopsis>
<para>
<function>shmop_open</function> can create or open a shared memory block.
</para>
<para>
<function>shmop_open</function> takes 4 parameters: key, which is the
system's id for the shared memory block, this parameter can be passed
as a decimal or hex. The second parameter are the flags that you can use:
<itemizedlist>
<listitem>
<simpara>
"a" for access (sets SHM_RDONLY for shmat)
use this flag when you need to open an existing shared memory segment for read only
</simpara>
</listitem>
<listitem>
<simpara>
"c" for create (sets IPC_CREATE)
use this flag when you need to create a new shared memory segment or if a
segment with the same key exists, try to open it for read and write
</simpara>
</listitem>
<listitem>
<simpara>
"w" for read &amp; write access
use this flag when you need to read and write to a shared memory segment, use this flag
in most cases.
</simpara>
</listitem>
<listitem>
<simpara>
"n" create a new memory segment (sets IPC_CREATE|IPC_EXCL)
use this flag when you want to create a new shared memory segment but if one
already exists with the same flag, fail. This is useful for security purposes, using this you
can prevent race condition exploits.
</simpara>
</listitem>
</itemizedlist>
The third parameter is the mode, which are the permissions that you
wish to assign to your memory segment, those are the same as permission
for a file. Permissions need to be passed in octal form ex. 0644.
The last parameter is size of the shared memory block you wish to create
in bytes.
<note><simpara>
Note: the 3rd and 4th should be entered as 0 if you are opening an
existing memory segment. On success <function>shmop_open</function> will
return an id that you can use to access the shared memory segment
you've created.
</simpara></note>
</para>
<para>
<example>
<title>Create a new shared memory block</title>
<programlisting role="php">
<![CDATA[
<?php
$shm_id = shmop_open(0x0fff, "c", 0644, 100);
?>
]]>
</programlisting>
</example>
</para>
<para>
This example opened a shared memory block with a system id of 0x0fff.
</para>
</refsect1>
</refentry>
<refentry id="function.shmop-read">
<refnamediv>
<refname>shmop_read</refname>
<refpurpose>Read data from shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>shmop_read</methodname>
<methodparam><type>int</type><parameter>shmid</parameter></methodparam>
<methodparam><type>int</type><parameter>start</parameter></methodparam>
<methodparam><type>int</type><parameter>count</parameter></methodparam>
</methodsynopsis>
<para>
<function>shmop_read</function> will read a string from shared memory block.
</para>
<para>
<function>shmop_read</function> takes 3 parameters: shmid, which is the shared
memory block identifier created by <function>shmop_open</function>, offset from
which to start reading and count on the number of bytes to read.
</para>
<para>
<example>
<title>Reading shared memory block</title>
<programlisting role="php">
<![CDATA[
<?php
$shm_data = shmop_read($shm_id, 0, 50);
?>
]]>
</programlisting>
</example>
</para>
<para>
This example will read 50 bytes from shared memory block and place the data
inside <literal>$shm_data</literal>.
</para>
</refsect1>
</refentry>
<refentry id="function.shmop-write">
<refnamediv>
<refname>shmop_write</refname>
<refpurpose>Write data into shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>shmop_write</methodname>
<methodparam><type>int</type><parameter>shmid</parameter></methodparam>
<methodparam><type>string</type><parameter>data</parameter></methodparam>
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
</methodsynopsis>
<para>
<function>shmop_write</function> will write a string into shared memory block.
</para>
<para>
<function>shmop_write</function> takes 3 parameters: shmid, which is the
shared memory block identifier created by <function>shmop_open</function>,
data, a string that you want to write into shared memory block and offset,
which specifies where to start writing data inside the shared memory segment.
</para>
<para>
<example>
<title>Writing to shared memory block</title>
<programlisting role="php">
<![CDATA[
<?php
$shm_bytes_written = shmop_write($shm_id, $my_string, 0);
?>
]]>
</programlisting>
</example>
</para>
<para>
This example will write data inside <literal>$my_string</literal> into
shared memory block, <literal>$shm_bytes_written</literal> will contain
the number of bytes written.
</para>
</refsect1>
</refentry>
<refentry id="function.shmop-size">
<refnamediv>
<refname>shmop_size</refname>
<refpurpose>Get size of shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>shmop_size</methodname>
<methodparam><type>int</type><parameter>shmid</parameter></methodparam>
</methodsynopsis>
<para>
<function>shmop_size</function> is used to get the size, in bytes of the
shared memory block.
</para>
<para>
<function>shmop_size</function> takes the shmid, which is the shared memory
block identifier created by <function>shmop_open</function>, the function
will return and int, which represents the number of bytes the shared memory
block occupies.
</para>
<para>
<example>
<title>Getting the size of the shared memory block</title>
<programlisting role="php">
<![CDATA[
<?php
$shm_size = shmop_size($shm_id);
?>
]]>
</programlisting>
</example>
</para>
<para>
This example will put the size of shared memory block identified by
<literal>$shm_id</literal> into <literal>$shm_size</literal>.
</para>
</refsect1>
</refentry>
<refentry id="function.shmop-delete">
<refnamediv>
<refname>shmop_delete</refname>
<refpurpose>Delete shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>shmop_delete</methodname>
<methodparam><type>int</type><parameter>shmid</parameter></methodparam>
</methodsynopsis>
<para>
<function>shmop_delete</function> is used to delete a shared memory block.
</para>
<para>
<function>shmop_delete</function> takes the shmid, which is the shared memory
block identifier created by <function>shmop_open</function>. On success 1 is
returned, on failure 0 is returned.
</para>
<para>
<example>
<title>Deleting shared memory block</title>
<programlisting role="php">
<![CDATA[
<?php
shmop_delete($shm_id);
?>
]]>
</programlisting>
</example>
</para>
<para>
This example will delete shared memory block identified by
<literal>$shm_id</literal>.
</para>
</refsect1>
</refentry>
<refentry id="function.shmop-close">
<refnamediv>
<refname>shmop_close</refname>
<refpurpose>Close shared memory block</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>shmop_close</methodname>
<methodparam><type>int</type><parameter>shmid</parameter></methodparam>
</methodsynopsis>
<para>
<function>shmop_close</function> is used to close a shared memory block.
</para>
<para>
<function>shmop_close</function> takes the shmid, which is the shared memory
block identifier created by <function>shmop_open</function>.
</para>
<para>
<example>
<title>Closing shared memory block</title>
<programlisting role="php">
<![CDATA[
<?php
shmop_close($shm_id);
?>
]]>
</programlisting>
</example>
</para>
<para>
This example will close shared memory block identified by <literal>$shm_id</literal>.
</para>
</refsect1>
</refentry>
</reference>
<!-- 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:"../../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
-->