<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.syncsemaphore.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'syncsemaphore.construct.php',
    1 => 'SyncSemaphore::__construct',
    2 => 'Constructs a new SyncSemaphore object',
  ),
  'up' => 
  array (
    0 => 'class.syncsemaphore.php',
    1 => 'SyncSemaphore',
  ),
  'prev' => 
  array (
    0 => 'class.syncsemaphore.php',
    1 => 'SyncSemaphore',
  ),
  'next' => 
  array (
    0 => 'syncsemaphore.lock.php',
    1 => 'SyncSemaphore::lock',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/sync/syncsemaphore/construct.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="syncsemaphore.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SyncSemaphore::__construct</h1>
  <p class="verinfo">(PECL sync &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">SyncSemaphore::__construct</span> &mdash; <span class="dc-title">Constructs a new SyncSemaphore object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-syncsemaphore.construct-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SyncSemaphore::__construct</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$name</code><span class="initializer"> = ?</span></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$initialval</code><span class="initializer"> = 1</span></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$autounlock</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong></span></span>)</div>

  <p class="simpara">
   Constructs a named or unnamed semaphore.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-syncsemaphore.construct-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">name</code></dt>
    <dd>
     <span class="simpara">
      The name of the semaphore if this is a named semaphore object.
     </span>
     <blockquote class="note"><p><strong class="note">Note</strong>: 
      <span class="simpara">
       If the name already exists, it must be able to be opened by the current user
       that the process is running as or an exception will be thrown with a meaningless
       error message.
      </span>
     </p></blockquote>
    </dd>
   
   
    <dt><code class="parameter">initialval</code></dt>
    <dd>
     <span class="simpara">
      The initial value of the semaphore. This is the number of locks that may be obtained.
     </span>
    </dd>
   
   
    <dt><code class="parameter">autounlock</code></dt>
    <dd>
     <span class="simpara">
      Specifies whether or not to automatically unlock the semaphore at the
      conclusion of the PHP script.
     </span>
     <div class="warning"><strong class="warning">Warning</strong>
      <p class="simpara">
       If an object is: A named semaphore with an autounlock of <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, the object is
       locked, and the PHP script concludes before the object is unlocked, then the
       underlying semaphore will end up in an inconsistent state.
      </p>
     </div>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-syncsemaphore.construct-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   The new <span class="classname"><a href="class.syncsemaphore.php" class="classname">SyncSemaphore</a></span> object.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-syncsemaphore.construct-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="simpara">
   An exception is thrown if the semaphore cannot be created or opened.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-syncsemaphore.construct-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="function"><strong>SyncSemaphore::__construct()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$semaphore </span><span style="color: #007700">= new </span><span style="color: #0000BB">SyncSemaphore</span><span style="color: #007700">(</span><span style="color: #DD0000">"LimitedResource_2clients"</span><span style="color: #007700">, </span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /><br />if (!</span><span style="color: #0000BB">$semaphore</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">lock</span><span style="color: #007700">(</span><span style="color: #0000BB">3000</span><span style="color: #007700">))<br />{<br />    echo </span><span style="color: #DD0000">"Unable to lock semaphore."</span><span style="color: #007700">;<br /><br />    exit();<br />}<br /><br /></span><span style="color: #FF8000">/* ... */<br /><br /></span><span style="color: #0000BB">$semaphore</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">unlock</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-syncsemaphore.construct-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="syncsemaphore.lock.php" class="methodname" rel="rdfs-seeAlso">SyncSemaphore::lock()</a> - Decreases the count of the semaphore or waits</span></li>
   <li><span class="methodname"><a href="syncsemaphore.unlock.php" class="methodname" rel="rdfs-seeAlso">SyncSemaphore::unlock()</a> - Increases the count of the semaphore</span></li>
  </ul>
 </div>


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