<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.event.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'event.add.php',
    1 => 'Event::add',
    2 => 'Makes event pending',
  ),
  'up' => 
  array (
    0 => 'class.event.php',
    1 => 'Event',
  ),
  'prev' => 
  array (
    0 => 'class.event.php',
    1 => 'Event',
  ),
  'next' => 
  array (
    0 => 'event.addsignal.php',
    1 => 'Event::addSignal',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/event/event/add.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="event.add" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Event::add</h1>
  <p class="verinfo">(PECL event &gt;= 1.2.6-beta)</p><p class="refpurpose"><span class="refname">Event::add</span> &mdash; <span class="dc-title">Makes event pending</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-event.add-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="methodname"><strong>Event::add</strong></span>(<span class="methodparam">
    
    <span class="type"><a href="language.types.float.php" class="type float">float</a></span> <code class="parameter">$timeout</code>
   <span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Marks event pending. Non-pending event will never occur, and the event
   callback will never be called. In conjunction with
   <span class="methodname"><a href="event.del.php" class="methodname">Event::del()</a></span>
   an event could be re-scheduled by user at any time.
  </p>
  <p class="para">
   If
   <span class="methodname"><strong>Event::add()</strong></span>
   is called on an already pending event, libevent will leave it pending and
   re-schedule it with the given timeout(if specified). If in this case
   timeout is not specified,
   <span class="methodname"><strong>Event::add()</strong></span>
   has no effect.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-event.add-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <dl>
   
    <dt>
     <code class="parameter">timeout</code>
    </dt>
    <dd>
     <p class="para">
      Timeout in seconds.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-event.add-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Gibt bei Erfolg <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> zurück. Bei einem Fehler wird <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> zurückgegeben.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-event.add-examples">
  <h3 class="title">Beispiele</h3>
  <div class="example" id="example-1">
   <p><strong>Beispiel #1 Adding a custom signal</strong></p>
   <div class="example-contents">
    <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*<br />Launch it in a terminal window:<br /><br />$ php examples/signal.php<br /><br />In another terminal window find out the pid and send SIGTERM, e.g.:<br /><br />$ ps aux | grep examp<br />ruslan    3976  0.2  0.0 139896 11256 pts/1    S+   10:25   0:00 php examples/signal.php<br />ruslan    3978  0.0  0.0   9572   864 pts/2    S+   10:26   0:00 grep --color=auto examp<br />$ kill -TERM 3976<br /><br />At the first terminal window you should catch the following:<br /><br />Caught signal 15<br />*/<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">MyEventSignal </span><span style="color: #007700">{<br />    private </span><span style="color: #0000BB">$base</span><span style="color: #007700">, </span><span style="color: #0000BB">$ev</span><span style="color: #007700">;<br /><br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">$base</span><span style="color: #007700">) {<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">base </span><span style="color: #007700">= </span><span style="color: #0000BB">$base</span><span style="color: #007700">;<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ev </span><span style="color: #007700">= </span><span style="color: #0000BB">Event</span><span style="color: #007700">::</span><span style="color: #0000BB">signal</span><span style="color: #007700">(</span><span style="color: #0000BB">$base</span><span style="color: #007700">, </span><span style="color: #0000BB">SIGTERM</span><span style="color: #007700">, array(</span><span style="color: #0000BB">$this</span><span style="color: #007700">, </span><span style="color: #DD0000">'eventSighandler'</span><span style="color: #007700">));<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ev</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">();<br />    }<br /><br />    public function </span><span style="color: #0000BB">eventSighandler</span><span style="color: #007700">(</span><span style="color: #0000BB">$no</span><span style="color: #007700">, </span><span style="color: #0000BB">$c</span><span style="color: #007700">) {<br />        echo </span><span style="color: #DD0000">"Caught signal </span><span style="color: #0000BB">$no</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">base</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exit</span><span style="color: #007700">();<br />    }<br />}<br /><br /></span><span style="color: #0000BB">$base </span><span style="color: #007700">= new </span><span style="color: #0000BB">EventBase</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$c    </span><span style="color: #007700">= new </span><span style="color: #0000BB">MyEventSignal</span><span style="color: #007700">(</span><span style="color: #0000BB">$base</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$base</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loop</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt
eine ähnliche Ausgabe wie:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Caught signal 15</pre>
</div>
   </div>
  </div>

  <div class="example" id="example-2">
   <p><strong>Beispiel #2 Adding a timer</strong></p>
   <div class="example-contents">
    <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$base </span><span style="color: #007700">= new </span><span style="color: #0000BB">EventBase</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$n </span><span style="color: #007700">= </span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">Event</span><span style="color: #007700">::</span><span style="color: #0000BB">timer</span><span style="color: #007700">(</span><span style="color: #0000BB">$base</span><span style="color: #007700">, function(</span><span style="color: #0000BB">$n</span><span style="color: #007700">) use (&amp;</span><span style="color: #0000BB">$e</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$n</span><span style="color: #DD0000"> seconds elapsed\n"</span><span style="color: #007700">;<br />    </span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">delTimer</span><span style="color: #007700">();<br />}, </span><span style="color: #0000BB">$n</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">$n</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$base</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loop</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt
eine ähnliche Ausgabe wie:</p></div>
   <div class="example-contents screen">
    <div class="examplescode"><pre class="examplescode">2 seconds elapsed</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-event.add-seealso">
  <h3 class="title">Siehe auch</h3>
  <ul class="simplelist">
   <li><span class="methodname"><strong>Event::add()</strong></span></li>
   <li><span class="methodname"><a href="event.del.php" class="methodname" rel="rdfs-seeAlso">Event::del()</a> - Makes event non-pending</span></li>
   <li><span class="methodname"><a href="event.signal.php" class="methodname" rel="rdfs-seeAlso">Event::signal()</a> - Constructs signal event object</span></li>
   <li><span class="methodname"><a href="event.timer.php" class="methodname" rel="rdfs-seeAlso">Event::timer()</a> - Constructs timer event object</span></li>
  </ul>
 </div>

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