The new Win32Service library

Par @jbnahan69
Logo Win32Service
Logo Win32Service

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 PHP.net 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 ?

Read also :

Author avatar
Jean-Baptiste Nahan

Consultant Expert Web, j'aide les entreprises ayant des difficultés avec leur projet Web (PHP, Symfony, Sylius).

@jbnahan69 | Macintoshplus | Linkedin | JB Dev Labs