win32_create_service

(PECL win32service >=0.1.0)

win32_create_serviceCreates a new service entry in the SCM database

Beschreibung

win32_create_service(array $details, string $machine = ?): void

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

Parameter-Liste

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 net command. The service must be unique (no two services can share the same name), and, ideally, should avoid having spaces in the name.

display

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

description

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

user

The 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.

path

The 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_order

Controls the load_order. This is not yet fully supported.

svc_type

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

start_type

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

error_control

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

delayed_start

If delayed_start 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.

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

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

base_priority

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

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

dependencies

To 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_delay

This 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 recovery_action_1 can be set to one of the constants defined in Win32 Recovery action.

recovery_action_2

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

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

recovery_action_3

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

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

recovery_reset_period

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

The default value is 86400.

recovery_enabled

Set 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.

machine

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

Rückgabewerte

Es wird kein Wert zurückgegeben.

Prior to version 1.0.0, gab im Erfolgsfall WIN32_NO_ERROR zurück oder false, wenn es ein Problem mit den Parametern gab oder einen Win32-Fehlercode im Fehlerfall.

Fehler/Exceptions

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

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

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

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

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

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

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

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

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

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

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

A Win32ServiceException is thrown on error.

Changelog

Version Beschreibung
PECL win32service 1.0.0 Throws a ValueError on invalid data in parameters, previously false was returned.
PECL win32service 1.0.0 Throws a Win32ServiceException on error, previously a Win32 Error Code was returned.
PECL win32service 1.0.0 The return type is now void, previously it was mixed.
PECL win32service 0.4.0 The dependencies, recovery_delay, recovery_action_1, recovery_action_2, recovery_action_3, recovery_reset_period, recovery_enabled, recovery_reboot_msg and recovery_command parameters have been added.

Beispiele

Beispiel #1 A win32_create_service() 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);
?>

Beispiel #2 A win32_create_service() 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);
?>

Beispiel #3 A win32_create_service() 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);
?>

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Notizen-App: was ist eure - ich komm immer wieder auf Keep zurück...

Hallo liebe Community, guten Abend, Notizen-App: was ist eure - ich komm immer wieder auf Keep zurück... was ist eure beste NoteTaking App!? i ...

Geschrieben von dhubs am 22.12.2024 23:05:11
Forum: Off-Topic Diskussionen
How to overcome Safari's iframe cookie block?

To overcome Safari's iframe cookie block, you can use the SameSite=None; Secure cookie attribute in conjunction with a third-party domain that sup ...

Geschrieben von Joniemartinez am 21.12.2024 13:28:24
Forum: HTML, JavaScript, AJAX, jQuery, CSS, Bootstrap, LESS
Probleme mit speichern in Datenbank in französisch

Les erreurs fréquentes lors de l'enregistrement de données dans une base de données incluent des problèmes de connexion, des erreurs de syntax ...

Geschrieben von Alice12 am 18.12.2024 05:07:21
Forum: PHP Developer Forum
Gibt es eine API zum Abrufen von PHP-Code-Referenzen?

PHP.net bietet eine umfassende Online-Dokumentation für PHP. Es gibt keine offizielle API zum Abrufen von PHP-Dokumentationen direkt, aber du kan ...

Geschrieben von Alice12 am 18.12.2024 05:03:27
Forum: PHP Developer Forum