<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.misc.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.sapi-windows-set-ctrl-handler.php',
    1 => 'sapi_windows_set_ctrl_handler',
    2 => 'Set or remove a CTRL event handler',
  ),
  'up' => 
  array (
    0 => 'ref.misc.php',
    1 => 'Sonstige Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.sapi-windows-generate-ctrl-event.php',
    1 => 'sapi_windows_generate_ctrl_event',
  ),
  'next' => 
  array (
    0 => 'function.sapi-windows-vt100-support.php',
    1 => 'sapi_windows_vt100_support',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/misc/functions/sapi-windows-set-ctrl-handler.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.sapi-windows-set-ctrl-handler" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sapi_windows_set_ctrl_handler</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.4.0, PHP 8)</p><p class="refpurpose"><span class="refname">sapi_windows_set_ctrl_handler</span> &mdash; <span class="dc-title">Set or remove a CTRL event handler</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sapi-windows-set-ctrl-handler-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sapi_windows_set_ctrl_handler</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span></span> <code class="parameter">$handler</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$add</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong></span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Sets or removes a <code class="literal">CTRL</code> event handler, which allows Windows
   CLI processes to intercept or ignore <code class="literal">CTRL+C</code> and
   <code class="literal">CTRL+BREAK</code> events. Note that in multithreaded environments,
   this is only possible when called from the main thread.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sapi-windows-set-ctrl-handler-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <dl>
   
    <dt><code class="parameter">handler</code></dt>
    <dd>
     <p class="para">
      A callback function to set or remove. If set, this function will be called
      whenever a
      <kbd class="keycombo">
       <kbd class="keycap">CTRL</kbd>
       +<kbd class="keycap">C</kbd>
      </kbd>
      or
      <kbd class="keycombo">
       <kbd class="keycap">CTRL</kbd>
       +<kbd class="keycap">BREAK</kbd>
      </kbd>
      event occurs.
      The function is supposed to have the following signature:
      <div class="methodsynopsis dc-description">
       <span class="methodname"><strong>handler</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$event</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

      <dl>
       
        <dt><code class="parameter">event</code></dt>
        <dd>
         <span class="simpara">
          The <kbd class="keycap">CTRL</kbd> event which has been received;
          either <strong><code><a href="reserved.constants.php#constant.php-windows-event-ctrl-c">PHP_WINDOWS_EVENT_CTRL_C</a></code></strong>
          or <strong><code><a href="reserved.constants.php#constant.php-windows-event-ctrl-break">PHP_WINDOWS_EVENT_CTRL_BREAK</a></code></strong>.
         </span>
        </dd>
       
      </dl>
      Setting a <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> <code class="parameter">handler</code> causes the process to ignore
      <kbd class="keycombo">
       <kbd class="keycap">CTRL</kbd>
       +<kbd class="keycap">C</kbd>
      </kbd>
      events, but not
      <kbd class="keycombo">
       <kbd class="keycap">CTRL</kbd>
       +<kbd class="keycap">BREAK</kbd>
      </kbd>
      events.
     </p>
    </dd>
   
   
    <dt><code class="parameter">add</code></dt>
    <dd>
     <p class="para">
      If <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, the handler is set. If <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, the handler is removed.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sapi-windows-set-ctrl-handler-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-function.sapi-windows-set-ctrl-handler-examples">
  <h3 class="title">Beispiele</h3>
  <div class="example" id="sapi-windows-set-ctrl-handler.example.basic">
   <p><strong>Beispiel #1 Basic <span class="function"><strong>sapi_windows_set_ctrl_handler()</strong></span> Usage</strong></p>
   <div class="example-contents"><p>
     This example shows how to intercept <code class="literal">CTRL</code> events.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">ctrl_handler</span><span style="color: #007700">(</span><span style="color: #0000BB">int $event</span><span style="color: #007700">)<br />{<br />    switch (</span><span style="color: #0000BB">$event</span><span style="color: #007700">) {<br />        case </span><span style="color: #0000BB">PHP_WINDOWS_EVENT_CTRL_C</span><span style="color: #007700">:<br />            echo </span><span style="color: #DD0000">"You have pressed CTRL+C\n"</span><span style="color: #007700">;<br />            break;<br />        case </span><span style="color: #0000BB">PHP_WINDOWS_EVENT_CTRL_BREAK</span><span style="color: #007700">:<br />            echo </span><span style="color: #DD0000">"You have pressed CTRL+BREAK\n"</span><span style="color: #007700">;<br />            break;<br />    }<br />}<br /><br /></span><span style="color: #0000BB">sapi_windows_set_ctrl_handler</span><span style="color: #007700">(</span><span style="color: #DD0000">'ctrl_handler'</span><span style="color: #007700">);<br />while (</span><span style="color: #0000BB">true</span><span style="color: #007700">); </span><span style="color: #FF8000">// infinite loop, so the handler can be triggered<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sapi-windows-set-ctrl-handler-seealso">
  <h3 class="title">Siehe auch</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.sapi-windows-generate-ctrl-event.php" class="function" rel="rdfs-seeAlso">sapi_windows_generate_ctrl_event()</a> - Send a CTRL event to another process</span></li>
  </ul>
 </div>


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