<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.sem.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.sem-get.php',
    1 => 'sem_get',
    2 => 'Get a semaphore id',
  ),
  'up' => 
  array (
    0 => 'ref.sem.php',
    1 => 'Semaphore Functions',
  ),
  'prev' => 
  array (
    0 => 'function.sem-acquire.php',
    1 => 'sem_acquire',
  ),
  'next' => 
  array (
    0 => 'function.sem-release.php',
    1 => 'sem_release',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/sem/functions/sem-get.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.sem-get" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sem_get</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">sem_get</span> &mdash; <span class="dc-title">Get a semaphore id</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sem-get-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sem_get</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.integer.php" class="type int">int</a></span> <code class="parameter">$max_acquire</code><span class="initializer"> = 1</span></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 class="initializer"> = 0666</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$auto_release</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong></span></span><br>): <span class="type"><span class="type"><a href="class.sysvsemaphore.php" class="type SysvSemaphore">SysvSemaphore</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>sem_get()</strong></span> returns an id that can be used to
   access the System V semaphore with the given <code class="parameter">key</code>.
  </p>
  <p class="simpara">
   A second call to <span class="function"><strong>sem_get()</strong></span> for the same key
   will return a different semaphore identifier, but both
   identifiers access the same underlying semaphore.
  </p>
  <p class="simpara">
   If <code class="parameter">key</code> is <code class="literal">0</code>, a new private semaphore
   is created for each call to <span class="function"><strong>sem_get()</strong></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sem-get-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">key</code></dt>
    <dd>
     <span class="simpara">
     </span>
    </dd>
   
   
    <dt><code class="parameter">max_acquire</code></dt>
    <dd>
     <span class="simpara">
      The number of processes that can acquire the semaphore simultaneously
      is set to <code class="parameter">max_acquire</code>.
     </span>
    </dd>
   
   
    <dt><code class="parameter">permissions</code></dt>
    <dd>
     <span class="simpara">
      The semaphore permissions. Actually this value is
      set only if the process finds it is the only process currently
      attached to the semaphore.
     </span>
    </dd>
   
   
    <dt><code class="parameter">auto_release</code></dt>
    <dd>
     <span class="simpara">
      Specifies if the semaphore should be automatically released on request
      shutdown.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sem-get-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   Returns a positive semaphore identifier on success, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on
   error.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.sem-get-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       On success, this function returns a <span class="classname"><a href="class.sysvsemaphore.php" class="classname">SysvSemaphore</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>
       The type of <code class="parameter">auto_release</code> has been changed from
       <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> to <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 notes" id="refsect1-function.sem-get-notes">
  <h3 class="title">Notes</h3>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    When using <span class="function"><strong>sem_get()</strong></span> to access a semaphore created
    outside PHP, note that the semaphore must have been created as a set of 3
    semaphores (for example, by specifying 3 as the <code class="literal">nsems</code>
    parameter when calling the C <code class="literal">semget()</code> function),
    otherwise PHP will be unable to access the semaphore.
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sem-get-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.sem-acquire.php" class="function" rel="rdfs-seeAlso">sem_acquire()</a> - Acquire a semaphore</span></li>
   <li><span class="function"><a href="function.sem-release.php" class="function" rel="rdfs-seeAlso">sem_release()</a> - Release a semaphore</span></li>
   <li><span class="function"><a href="function.ftok.php" class="function" rel="rdfs-seeAlso">ftok()</a> - Convert a pathname and a project identifier to a System V IPC key</span></li>
  </ul>
 </div>


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