<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Create or open shared memory block</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.shmop-delete.html">shmop_delete</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.shmop-read.html">shmop_read</a></div> <div class="up"><a href="ref.shmop.html">Shared Memory Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.shmop-open" class="refentry"> <div class="refnamediv"> <h1 class="refname">shmop_open</h1> <p class="verinfo">(PHP 4 >= 4.0.4, PHP 5)</p><p class="refpurpose"><span class="refname">shmop_open</span> — <span class="dc-title">Create or open shared memory block</span></p> </div> <div class="refsect1 description" id="refsect1-function.shmop-open-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>shmop_open</strong></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$key</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$flags</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span> )</div> <p class="para rdfs-comment"> <span class="function"><strong>shmop_open()</strong></span> can create or open a shared memory block. </p> </div> <div class="refsect1 parameters" id="refsect1-function.shmop-open-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">key</code></em></span> <dd> <p class="para"> System's id for the shared memory block. Can be passed as a decimal or hex. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">flags</code></em></span> <dd> <p class="para"> The flags that you can use: <ul class="itemizedlist"> <li class="listitem"> <span class="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 </span> </li> <li class="listitem"> <span class="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 </span> </li> <li class="listitem"> <span class="simpara"> "w" for read & write access use this flag when you need to read and write to a shared memory segment, use this flag in most cases. </span> </li> <li class="listitem"> <span class="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. </span> </li> </ul> </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">mode</code></em></span> <dd> <p class="para"> 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, like for example <em>0644</em> </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">size</code></em></span> <dd> <p class="para"> The size of the shared memory block you wish to create in bytes </p> </dd> </dt> </dl> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Note: the 3rd and 4th should be entered as 0 if you are opening an existing memory segment. </p> </p></blockquote> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.shmop-open-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> On success <span class="function"><strong>shmop_open()</strong></span> will return an id that you can use to access the shared memory segment you've created. <strong><code>FALSE</code></strong> is returned on failure. </p> </div> <div class="refsect1 examples" id="refsect1-function.shmop-open-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-3725"> <p><strong>Example #1 Create a new shared memory block</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$shm_key </span><span style="color: #007700">= </span><span style="color: #0000BB">ftok</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">, </span><span style="color: #DD0000">'t'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$shm_id </span><span style="color: #007700">= </span><span style="color: #0000BB">shmop_open</span><span style="color: #007700">(</span><span style="color: #0000BB">$shm_key</span><span style="color: #007700">, </span><span style="color: #DD0000">"c"</span><span style="color: #007700">, </span><span style="color: #0000BB">0644</span><span style="color: #007700">, </span><span style="color: #0000BB">100</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> This example opened a shared memory block with a system id returned by <span class="function"><a href="function.ftok.html" class="function">ftok()</a></span>. </p> </div> <div class="refsect1 seealso" id="refsect1-function.shmop-open-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.shmop-close.html" class="function" rel="rdfs-seeAlso">shmop_close()</a> - Close shared memory block</span></li> <li class="member"> <span class="function"><a href="function.shmop-delete.html" class="function" rel="rdfs-seeAlso">shmop_delete()</a> - Delete shared memory block</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.shmop-delete.html">shmop_delete</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.shmop-read.html">shmop_read</a></div> <div class="up"><a href="ref.shmop.html">Shared Memory Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>