<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.shmop.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.shmop-open.php',
    1 => 'shmop_open',
    2 => 'Create or open shared memory block',
  ),
  'up' => 
  array (
    0 => 'ref.shmop.php',
    1 => 'Shared Memory 函数',
  ),
  'prev' => 
  array (
    0 => 'function.shmop-delete.php',
    1 => 'shmop_delete',
  ),
  'next' => 
  array (
    0 => 'function.shmop-read.php',
    1 => 'shmop_read',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/shmop/functions/shmop-open.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.shmop-open" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">shmop_open</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">shmop_open</span> &mdash; <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">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>shmop_open</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$key</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$mode</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$permissions</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$size</code></span><br>): <span class="type"><span class="type"><a href="class.shmop.php" class="type Shmop">Shmop</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">
   <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">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">key</code></dt>
     <dd>
      <span class="simpara">
       System&#039;s id for the shared memory block.
       Can be passed as a decimal or hex.
      </span>
     </dd>
    
    
     <dt><code class="parameter">mode</code></dt>
     <dd>
      <p class="para">
       The flags that you can use:
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          &quot;a&quot; 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">
          &quot;c&quot; 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">
          &quot;w&quot; 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.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          &quot;n&quot; 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><code class="parameter">permissions</code></dt>
     <dd>
      <span class="simpara">
       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 <code class="literal">0644</code>
      </span>
     </dd>
    
    
     <dt><code class="parameter">size</code></dt>
     <dd>
      <span class="simpara">
       The size of the shared memory block you wish to create in bytes
      </span>
     </dd>
    
   </dl>
   <blockquote class="note"><p><strong class="note">注意</strong>: 
    <span class="simpara">
     Note: the 3rd and 4th should be entered as 0 if you are opening an
     existing memory segment.
    </span>
   </p></blockquote>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.shmop-open-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="simpara">
   On success <span class="function"><strong>shmop_open()</strong></span> will return a <span class="classname"><a href="class.shmop.php" class="classname">Shmop</a></span> instance that you can
   use to access the shared memory segment you&#039;ve created. <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is
   returned on failure.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.shmop-open-errors">
  <h3 class="title">错误／异常</h3>
  <p class="simpara">
   If <code class="parameter">mode</code> is invalid, or <code class="parameter">size</code> is less than or equal to zero,
   a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> is thrown.
   On other failures, <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> is emitted.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.shmop-open-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       On success, this function returns an <span class="classname"><a href="class.shmop.php" class="classname">Shmop</a></span> instance now;
       previously, a <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> was returned.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       If <code class="parameter">mode</code> is invalid, or <code class="parameter">size</code> is less than or equal to zero,
       a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> is thrown; previously <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> was emitted instead,
       and the function returned <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.shmop-open-examples">
  <h3 class="title">示例</h3>
  <div class="example" id="example-1">
   <p><strong>示例 #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">&lt;?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">?&gt;</span></span></code></div>
   </div>

  </div>
  <p class="simpara">
   This example opened a shared memory block with a system id returned by
   <span class="function"><a href="function.ftok.php" class="function">ftok()</a></span>.
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.shmop-open-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.shmop-close.php" class="function" rel="rdfs-seeAlso">shmop_close()</a> - Close shared memory block</span></li>
   <li><span class="function"><a href="function.shmop-delete.php" class="function" rel="rdfs-seeAlso">shmop_delete()</a> - Delete shared memory block</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>