PHP.nl

win32_create_service

win32_create_service

Creates a new service entry in the SCM database

void **win32_create_service** array $details string $machine

Attempts to add a service into the SCM database. Administrative privileges are required for this to succeed.

details An array of service details:

  `service`
       The short name of the service.  This is the name that you
       will use to control the service using the 
       command.  The service must be unique (no two services can share the
       same name), and, ideally, should avoid having spaces in the name.
      `net`

displayThe display name of the service. This is the name that you will see in the Services Applet.

descriptionThe long description of the service. This is the description that you will see in the Services Applet.

userThe name of the user account under which you want the service to run. If omitted, the service will run as the LocalSystem account. If the username is specified, you must also provide a password.

password The password that corresponds to the . user

pathThe full path to the executable module that will be launched when the service is started. If omitted, the path to the current PHP process will be used.

params Command line parameters to pass to the service when it starts. If you want to run a PHP script as the service, then the first parameter should be the full path to the PHP script that you intend to run. If the script name or path contains spaces, then wrap the full path to the PHP script with . "

load_orderControls the load_order. This is not yet fully supported.

svc_type Sets the service type. If omitted, the default value is . Don't change this unless you know what you're doing. WIN32_SERVICE_WIN32_OWN_PROCESS

start_type Specifies how the service should be started. The default is which means the service will be launched when the machine starts up. WIN32_SERVICE_AUTO_START

error_control Informs the SCM what it should do when it detects a problem with the service. The default is . Changing this value is not yet fully supported. WIN32_SERVER_ERROR_IGNORE

delayed_start If is set to true, then this will inform the SCM that this service should be started after other auto-start services are started plus a short delay. delayed_start

       Any service can be marked as a delayed auto-start service; however,
       this setting has no effect unless the service's
        is
       .
      `start_type``WIN32_SERVICE_AUTO_START`

This setting is only applicable on Windows Vista and Windows Server 2008 or greater.

base_priorityTo reduce the impact on processor utilisation, it may be necessary to set a base priority lower than normal.

       The  can be set to one of the
       constants define in
       .
      `base_priority`Win32 Base Priority Classes

dependenciesTo define the dependencies for your service, it may be necessary to set this parameter to the list of the services names in an array.

recovery_delayThis parameter defines the delay between the fail and the execution of recovery action. The value is in milliseconds.

The default value is 60000.

recovery_action_1 The action will be executed on first failure. The default value is . WIN32_SC_ACTION_NONE

       The  can be set to one of the
       constants defined in
       .
      `recovery_action_1`Win32 Recovery action

recovery_action_2 The action will be executed on second failure. The default value is . WIN32_SC_ACTION_NONE

       The  can be set to one of the
       constants defined in
       .
      `recovery_action_2`Win32 Recovery action

recovery_action_3 The action will be executed on next failures. The default value is . WIN32_SC_ACTION_NONE

       The  can be set to one of the
       constants defined in
       .
      `recovery_action_3`Win32 Recovery action

recovery_reset_periodThe failure count will be reset after the delay defined in the parameter. The delay is expirement in seconds.

       The default value is .
      `86400`

recovery_enabledSet this parameter at true to enable the recovery settings, false to disable.

The default value is false

recovery_reboot_msg Set this parameter to define the message saved into the Windows Event Log before the reboot. Used only if one action is set to . WIN32_SC_ACTION_REBOOT

recovery_command Set this parameter to define the command executed when one action is defined on
. WIN32_SC_ACTION_RUN_COMMAND

machineThe optional machine name on which you want to create a service. If omitted, it will use the local machine.

return.void

Prior to version 1.0.0, win32service.noerror.false.error

A is thrown if the value of parameter is empty. ValueError``service

A is thrown if the value of parameter is missing or empty. ValueError``path

A is thrown if the value of parameter is wrong. ValueError``svc_type

A is thrown if the value of parameter is wrong. ValueError``start_type

A is thrown if the value of parameter is wrong. ValueError``error_control

A is thrown if the value of parameter is wrong. ValueError``base_priority

A is thrown if the value of parameter is not between 0 and PHP_INT_MAX. ValueError``recovery_delay

A is thrown if the value of parameter is wrong. ValueError``recovery_action_1

A is thrown if the value of parameter is wrong. ValueError``recovery_action_2

A is thrown if the value of parameter is wrong. ValueError``recovery_action_3

A is thrown if the value of parameter is not between 0 and PHP_INT_MAX. ValueError``recovery_reset_period

A is thrown on error. Win32ServiceException

Voorbeeld: A example

Create a service with the short name 'dummyphp'.

<?php
$x = win32_create_service(array(
    'service'     => 'dummyphp',                                           // the name of your service
    'display'     => 'sample dummy PHP service',                           // short description
    'description' => 'This is a dummy Windows service created using PHP.', // long description
    'params'      => '"' . __FILE__ . '"  run',                            // path to the script and parameters
));
debug_zval_dump($x);
?>

Voorbeeld: A example with dependencies

Create a service with the short name 'dummyphp' and dependencies.

<?php
$x = win32_create_service(array(
    'service'      => 'dummyphp',                                           // the name of your service
    'display'      => 'sample dummy PHP service',                           // short description
    'description'  => 'This is a dummy Windows service created using PHP.', // long description
    'params'       => '"' . __FILE__ . '"  run',                            // path to the script and parameters
    'dependencies' => array("Netman"),                                      // The list of the dependencies 
));
debug_zval_dump($x);
?>

Voorbeeld: A example with recovery

Create a service with the short name 'dummyphp' and recovery settings.

<?php
$x = win32_create_service(array(
    'service'               => 'dummyphp',                                           // the name of your service
    'display'               => 'sample dummy PHP service',                           // short description
    'description'           => 'This is a dummy Windows service created using PHP.', // long description
    'params'                => '"' . __FILE__ . '"  run',                            // path to the script and parameters
    'recovery_delay'        => 120000,                                               // Recovery action is executed after 2 minutes
    'recovery_action_1'     => WIN32_SC_ACTION_RESTART,                              // On first failure, restart the service
    'recovery_action_2'     => WIN32_SC_ACTION_RUN_COMMAND,                          // On second failure, execute the commmand
    'recovery_action_3'     => WIN32_SC_ACTION_NONE,                                 // On other failure, do nothing
    'recovery_reset_period' => 86400,                                                // Reset the fail counter after 1 day
    'recovery_enabled'      => true,                                                 // Enable the recovery parameter
    'recovery_reboot_msg'   => null,                                                 // Do not define a reboot message, it's not needed here
    'recovery_command'      => "c:\clean-service.bat",                               // When the action is WIN32_SC_ACTION_RUN_COMMAND, execute this command
));
debug_zval_dump($x);
?>

win32_delete_serviceWin32 Base Priority ClassesWin32 Recovery actionWin32 Error Codes