Archives par mot-clé : Windows

Projet Win32Service

Pour ceux qui ne le connaissent pas encore, ce projet permet l’exécution de script PHP en tant que service Windows. C’est un équivalent à systemd sous Linux.

Fin 2018, le projet a connu quelques changements, comme le déplacement du dépôt vers une entité indépendante du sponsor, l’ajout d’un nouveau site web et la sortie d’une librairie facilitant l’utilisation de l’extension.

La version 0.4.0 de l’extension PHP est en cours de développement, de nouvelles fonctionnalités sont déjà développées, mais il est toujours possible d’en proposer de nouvelles. La date de sortie n’est pas encore définie.

The new Win32Service library

Today, I want to write a new blog post for a new library. This library is written in PHP and need the Win32Service extension for PHP.

Why this library ? The goal is eased to use the Win32Service extension of separate clearly the two most important part provided by this extension.

The first part is the service management. This can be split in two subparts (register and unregister a service for first and start, pause, continue and stop the service in the second). There’s scripts need an elevated right on the server. Automatically, the security approach allows this usage only in the command line (cli SAPI).

The second part is the service running. This part assumes only the PHP script executed when the service state is « running ».

When you read the official documentation available in the website, this different usage is not clearly defined. Many other points are in favor of the library. The full-oriented object is available with the library. An abstract class is provided for the service running. The access denied or service not found errors are converted in special exception and other errors in generic exception provided by the library.

In the execution case, the abstract class provides many hooks to execute some code before the changing of service state. The typical use case is opening a database connexion in start or continue, close-it in pause or stop…

Now with this library, you can write a Windows service easily.
The library is available here with examples. How did you manage your PHP service on Windows Server ?