<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.win32service.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.win32-start-service-ctrl-dispatcher.php',
    1 => 'win32_start_service_ctrl_dispatcher',
    2 => 'Registers the script with the SCM, so that it can act as the service with the given name',
  ),
  'up' => 
  array (
    0 => 'ref.win32service.php',
    1 => 'win32service Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.win32-start-service.php',
    1 => 'win32_start_service',
  ),
  'next' => 
  array (
    0 => 'function.win32-stop-service.php',
    1 => 'win32_stop_service',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/win32service/functions/win32-start-service-ctrl-dispatcher.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.win32-start-service-ctrl-dispatcher" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">win32_start_service_ctrl_dispatcher</h1>
  <p class="verinfo">(PECL win32service &gt;=0.1.0)</p><p class="refpurpose"><span class="refname">win32_start_service_ctrl_dispatcher</span> &mdash; <span class="dc-title">Registers the script with the SCM, so that it can act as the service with the given name</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.win32-start-service-ctrl-dispatcher-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>win32_start_service_ctrl_dispatcher</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>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$gracefulMode</code><span class="initializer"> = true</span></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>


  <p class="para rdfs-comment">
   When launched via the Service Control Manager, a service process is
   required to &quot;check-in&quot; with it to establish service monitoring and
   communication facilities.  This function performs the check-in by spawning
   a thread to handle the lower-level communication with the service control
   manager.
  </p>
  <p class="para">
   Once started, the service process should do 2 things. The first is to tell
   the Service Control Manager that the service is running. This is achieved
   by calling <span class="function"><a href="function.win32-set-service-status.php" class="function">win32_set_service_status()</a></span> with the
   <strong><code><a href="win32service.constants.php#constant.win32-service-running">WIN32_SERVICE_RUNNING</a></code></strong> constant. If you need to perform
   some lengthy process before the service is actually running, then you can
   use the <strong><code><a href="win32service.constants.php#constant.win32-service-start-pending">WIN32_SERVICE_START_PENDING</a></code></strong> constant. The
   second is to continue to check-in with the service control manager so that
   it can determine if it should terminate. This is achieved by periodically
   calling <span class="function"><a href="function.win32-get-last-control-message.php" class="function">win32_get_last_control_message()</a></span> and handling the
   return code appropriately.
  </p>

  <div class="caution"><strong class="caution">Attenzione</strong>
   <p class="para">
    Since version 0.2.0, this function work only in &quot;cli&quot; SAPI. On other SAPI 
    this function is disabled.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.win32-start-service-ctrl-dispatcher-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">name</code></dt>
     <dd>
      <p class="para">
       The short-name of the service, as registered by
       <span class="function"><a href="function.win32-create-service.php" class="function">win32_create_service()</a></span>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">gracefulMode</code></dt>
     <dd>
      <p class="para">
       <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> for exit graceful. <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> for exit with error. See 
       <span class="function"><a href="function.win32-set-service-exit-mode.php" class="function">win32_set_service_exit_mode()</a></span> for more details.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.win32-start-service-ctrl-dispatcher-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Nessun valore viene restituito.
  </p>
  <p class="para">
    Prior to version 1.0.0, returned <strong><code><a href="win32service.constants.php#constant.win32-no-error">WIN32_NO_ERROR</a></code></strong> on success, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> if there is a problem with the parameters or a <a href="win32service.constants.php#win32service.constants.errors" class="link">Win32 Error Code</a> on failure.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.win32-start-service-ctrl-dispatcher-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <p class="para">
   Prior to version 1.0.0, if the SAPI is not <code class="literal">&quot;cli&quot;</code>, this function emits an 
   <strong><code><a href="errorfunc.constants.php#constant.e-error">E_ERROR</a></code></strong> level error.
  </p>
   <p class="para">
    As of version 1.0.0, will throw a 
    <span class="classname"><a href="class.win32serviceexception.php" class="classname">Win32ServiceException</a></span> if SAPI is not 
    <code class="literal">&quot;cli&quot;</code>
   </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.win32-start-service-ctrl-dispatcher-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Versione</th>
       <th>Descrizione</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL win32service 1.0.0</td>
       <td>
        Throws a <span class="classname"><a href="class.valueerror.php" class="classname">ValueError</a></span> on invalid data in parameters,
        previously <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> was returned.
       </td>
      </tr>

      <tr>
       <td>PECL win32service 1.0.0</td>
       <td>
        Throws a <span class="classname"><a href="class.win32serviceexception.php" class="classname">Win32ServiceException</a></span> on error,
        previously a 
        <a href="win32service.constants.php#win32service.constants.errors" class="link">Win32 Error Code</a>
        was returned.
       </td>
      </tr>

      <tr>
       <td>PECL win32service 1.0.0</td>
       <td>
        The return type is now <span class="type"><span class="type"><a href="language.types.void.php" class="type void">void</a></span></span>, previously it was <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span>.
       </td>
      </tr>

      <tr>
       <td>PECL win32service 0.4.0</td>
       <td>
        The parameter <code class="parameter">gracefulMode</code> has been added.
       </td>
      </tr>

      <tr>
       <td>PECL win32service 0.2.0</td>
       <td>
        This function works only in the <code class="literal">&quot;cli&quot;</code> SAPI.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.win32-start-service-ctrl-dispatcher-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 A <span class="function"><strong>win32_start_service_ctrl_dispatcher()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     Check if the service is runnig under the SCM.
    </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">if (!</span><span style="color: #0000BB">win32_start_service_ctrl_dispatcher</span><span style="color: #007700">(</span><span style="color: #DD0000">'dummyphp'</span><span style="color: #007700">)) {<br />  die(</span><span style="color: #DD0000">"I'm probably not running under the service control manager"</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">win32_set_service_status</span><span style="color: #007700">(</span><span style="color: #0000BB">WIN32_SERVICE_START_PENDING</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Some lengthy process to get this service up and running.<br /><br /></span><span style="color: #0000BB">win32_set_service_status</span><span style="color: #007700">(</span><span style="color: #0000BB">WIN32_SERVICE_RUNNING</span><span style="color: #007700">);<br /><br />while (</span><span style="color: #0000BB">WIN32_SERVICE_CONTROL_STOP </span><span style="color: #007700">!= </span><span style="color: #0000BB">win32_get_last_control_message</span><span style="color: #007700">()) {<br />  </span><span style="color: #FF8000"># do some work here, trying not to take more than around 30 seconds<br />  # before coming back into the loop again<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.win32-start-service-ctrl-dispatcher-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.win32-set-service-status.php" class="function" rel="rdfs-seeAlso">win32_set_service_status()</a> - Update the service status</span></li>
    <li><span class="function"><a href="function.win32-get-last-control-message.php" class="function" rel="rdfs-seeAlso">win32_get_last_control_message()</a> - Returns the last control message that was sent to this service</span></li>
    <li><span class="function"><a href="function.win32-set-service-exit-mode.php" class="function" rel="rdfs-seeAlso">win32_set_service_exit_mode()</a> - Define or return the exit mode for the current running service</span></li>
    <li><span class="function"><a href="function.win32-set-service-exit-code.php" class="function" rel="rdfs-seeAlso">win32_set_service_exit_code()</a> - Define or return the exit code for the current running service</span></li>
    <li><a href="win32service.constants.php#win32service.constants.errors" class="link">Win32 Error Codes</a></li>
   </ul>
  </p>
 </div>


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