Code Monkey home page Code Monkey logo

win32service's Introduction

Build status License Documentation

Win32Service

The win32service extension is a Windows-specific extension that allows PHP to communicate with the Service Control Manager to start, stop, register and unregister the services, and even allows your PHP scripts to run as a service.

CAUTION : this extension version work only with PHP 8.x.

The version 0.4.x work with PHP 7.x.x branch. The version 1.0.x work with PHP 8.0.

Documentation

See: https://win32service.github.io/

News

For project news, search on Twitter: https://twitter.com/hashtag/Win32Service.

win32service's People

Contributors

alphp avatar eionrobb avatar macintoshplus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

win32service's Issues

All example not work with V1

PHP: 8.0.3
Win32Service: 1.0.0
Exemples: from v1.x Git branch.

When I try to run exemple, I have always a Win32ServiceException.

C:\Sites\wwwroot\win32service-1.0.x\examples>php80 object_exemple\WinServiceAdmin.php register
PHP Fatal error:  Uncaught Win32ServiceException: Error service does not exist in C:\Sites\wwwroot\win32service-1.0.x\examples\object_exemple\config.php:116
Stack trace:
#0 C:\Sites\wwwroot\win32service-1.0.x\examples\object_exemple\config.php(116): win32_query_service_status('WindowsServiceP...')
#1 C:\Sites\wwwroot\win32service-1.0.x\examples\object_exemple\config.php(86): win32service\WinServiceAbstract->update_service_status()
#2 C:\Sites\wwwroot\win32service-1.0.x\examples\object_exemple\WinServiceAdmin.php(54): win32service\WinServiceAbstract->__construct(Array, 'register')
#3 {main}
  thrown in C:\Sites\wwwroot\win32service-1.0.x\examples\object_exemple\config.php on line 116

Fatal error: Uncaught Win32ServiceException: Error service does not exist in C:\Sites\wwwroot\win32service-1.0.x\examples\object_exemple\config.php:116
Stack trace:
#0 C:\Sites\wwwroot\win32service-1.0.x\examples\object_exemple\config.php(116): win32_query_service_status('WindowsServiceP...')
#1 C:\Sites\wwwroot\win32service-1.0.x\examples\object_exemple\config.php(86): win32service\WinServiceAbstract->update_service_status()
#2 C:\Sites\wwwroot\win32service-1.0.x\examples\object_exemple\WinServiceAdmin.php(54): win32service\WinServiceAbstract->__construct(Array, 'register')
#3 {main}
  thrown in C:\Sites\wwwroot\win32service-1.0.x\examples\object_exemple\config.php on line 116

Can't use in embed sapi

I'm using the "embed" sapi, from the php_embed.c code that comes with PHP, embedded using embeder2 (https://github.com/RDashINC/embeder2), however win32service rejects anything that isn't the "cli" sapi. I recompiled win32service without the check for "cli" and it runs with the embeder2 exe fine.

Is it possible to remove the "cli" check altogether?

Support for adding Dependencies

It would be most helpful to add support for dependencies. For example, if you are building a service that relies on a mysql database, or any other service to be up and running before it makes sense for your service to start.

Is this a possibility?

Compilation for PHP7.4 in VC15 ?

Hi, I was glad to see about your job on win32service, thanks a lot for this !
However, having installed php7.4, I noticed your related dll are compiled in vs16.. ?
I'm sure there is a reason for this, however, my own PHP is compiled on VC15, as it was done for the 7.3 version.
Could you please push the dll compiled for 7.4, in VC15 please (TS-x86 in my case, but I'm sure all versions will please others than me ;) ? (I'm terribly bad in compiling... Otherwise, I would have done this by myself :/)

Thanks a lot !!

Allow Start/Stop/Pause service without admin account

Since the version 0.1.0, the user running PHP does a local administrator.

But, it's possible to change the ACL on a Windows Service for allow a non admin account to control it. Best practices and guidance for writers of service discretionary access control lists.

Howto do this case with this extension ?
My proposal is use the branche "less_admin" from this repository for this use case.
With this branche, the administrator right is needed for create and delete service.
Patch source : https://bugs.php.net/bug.php?id=70961

This use case is generic ? Or two posibility is needed ?

Ping @alphp

Characters encoding problems

Hi,

I've got a problem with characters encodings when displayed in Windows service description :
image
Here "é" characters is replaceed with bad ones...

My PHP file is correctly encoded in UTF8.

PHP 8.3 support

I have been trying to update one of our applications from PHP 7.4 to PHP 8.3. I have tried the versions from #75

  • The extension will load, and shows in php -m
  • using the symfony bundle I can register & unregister service(s)

however I cannot get the service to start & run.

Windows event viewer shows:-
A timeout was reached (300000 milliseconds) while waiting for the Test Service service to connect.

The log file shows:-

[2024-03-07T11:07:21.038914+00:00] console.CRITICAL: Error thrown while running command "win32service:run TestService 0". Message: "Error on start service controller" {"exception":"[object] (Win32Service\\Exception\\Win32ServiceException(code: 0): Error on start service controller at C:\\Src\\BitBucket\\TestService\\vendor\\win32service\\service-library\\lib\\Model\\AbstractServiceRunner.php:116)","command":"win32service:run TestService 0","message":"Error on start service controller"} {"threadNumber":0}

OS Name: Microsoft Windows 10 Enterprise
Version: 10.0.19045 Build 19045

php -v PHP 8.3.2 (cli) (built: Jan 16 2024 20:48:07) (NTS Visual C++ 2019 x64) Copyright (c) The PHP Group Zend Engine v4.3.2, Copyright (c) Zend Technologies with Zend OPcache v8.3.2, Copyright (c), by Zend Technologies

php -i

win32service

The maintainer needs your feedback (good or bad), please send it to: [email protected]
Please report your bugs with this extension here : https://bugs.php.net/
Home page: http://win32service.mactronique.fr/
Library for help you to use this extension: https://github.com/win32service/service-library and https://github.com/win32service/Win32ServiceBundle for Symfony

Win32 Service support => enabled
Version => 1.0.2
Current SAPI => cli

Function => State for the current SAPI
win32_start_service_ctrl_dispatcher => enabled
win32_set_service_status => enabled
win32_get_last_control_message => enabled
win32_set_service_exit_mode => enabled
win32_set_service_exit_code => enabled
win32_create_service => enabled
win32_delete_service => enabled
win32_query_service_status => enabled
win32_start_service => enabled
win32_stop_service => enabled
win32_pause_service => enabled
win32_continue_service => enabled
win32_send_custom_control => enabled

Wait for the connection timeout (60,000 milliseconds) for the PHP service for tests service.

PS D:\webTestProject\php_win32service\examples> php .\managementActions.php start my_test_service
Service : localhost\my_test_service
Error : (1053) Win32Service\Exception\ServiceStateActionException: Unable to start service
PS D:\webTestProject\php_win32service\examples>

windows Event viewer:
Wait for the connection timeout (60,000 milliseconds) for the PHP service for tests service.
I used administrator to open the installation but could not start.

New release supporting php 8.2

Hi. I just downloaded php_win32service-8.1-nts-vs16-x86.dll from https://github.com/win32service/win32service/releases and put it into php 8.2, but looks like the extension was not loaded:

PHP Fatal error:  Uncaught Error: Call to undefined function win32_query_service_status()

Does it need a new binary release to support php 8.2? I see the master branch has this commit: 527c27d try PHP 8.2 build

Edit: I just found these errors on php start up:

PHP Warning:  PHP Startup: win32service: Unable to initialize module
Module compiled with module API=20210902
PHP    compiled with module API=20220829
These options need to match
 in Unknown on line 0

Extension 'win32service' not present.

I've installed as it's given in readme section, but while running 'php --ri win32service' im getting Extension 'win32service' not present.

Please guide me whats im doing wrong.

Below steps i've followed for installation.

a) downloaded the Extenstion & unzip.
b) copy pasted dll files into php/ext dir.
c) in php.ini pasted this line extension = php_win32service-7.0-ts-vc14-x86.dll

Access denied on service registration

When I use the Win32ServiceBundle, I have this error from Win32Extension:

Configuration:

win32_service:
  windows_local_encoding: ISO-8859-1
  services:
    - service_id: "runner"
      displayed_name: "runner"
      recovery:
        enable: true # The recovery action is disabled
        delay: 60000 # The delay before run action (in millisecond)
        action1: 2 # The action for the first fail
        action2: 2 # The action for the second fail
        action3: 2 # The action for the next fail
        reset_period: 5 # The period before reset the fail count (in minutes)
      dependencies: # The list of service depends
        - Netman # An example of dependency.

Result

>php81 bin\console win32service:register -vvv
^ Win32ServiceException {#160
  #message: "Error access denied"
  #code: 5
  #file: "C:\Sites\wwwroot\runner\vendor\win32service\service-library\lib\Service\ServiceAdminManager.php"
  #line: 48
  trace: {
    C:\Sites\wwwroot\runner\vendor\win32service\service-library\lib\Service\ServiceAdminManager.php:48 { …}
    C:\Sites\wwwroot\runner\vendor\win32service\win32servicebundle\lib\Command\RegisterServiceCommand.php:115 { …}
    C:\Sites\wwwroot\runner\vendor\symfony\console\Command\Command.php:308 { …}
    C:\Sites\wwwroot\runner\vendor\symfony\console\Application.php:1020 { …}
    C:\Sites\wwwroot\runner\vendor\symfony\framework-bundle\Console\Application.php:94 { …}
    C:\Sites\wwwroot\runner\vendor\symfony\console\Application.php:299 { …}
    C:\Sites\wwwroot\runner\vendor\symfony\framework-bundle\Console\Application.php:80 { …}
    C:\Sites\wwwroot\runner\vendor\symfony\console\Application.php:171 { …}
    C:\Sites\wwwroot\runner\vendor\symfony\runtime\Runner\Symfony\ConsoleApplicationRunner.php:54 { …}
    C:\Sites\wwwroot\runner\vendor\autoload_runtime.php:29 { …}
    C:\Sites\wwwroot\runner\bin\console:11 {
      ›
      › require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
      ›
      arguments: {
        "C:\Sites\wwwroot\runner\vendor\autoload_runtime.php"
      }
    }
  }
}
 Error : inference_runner(5) Access to service inference_runner is denied
1 service(s) processed

image

Can I build it on Linux ?

I would to install the win32service extension on a Linux server to run a static analysis on my source code which will be then deployes to a Windows system.
Could I build that extension on Linux ?
The phpize command returns an error "Cannot find config.m4".

crashes phpinfo( INFO_MODULES )

Version 0.4.0 (Feb 2019) will crash phpinfo() under PHP 7.3 and 7.2

Can be circumvented by unselecting INFO_MODULES, or by disabling the win32service extension.

Anything greater 7.3.6 oder 7.2.19 is affected.

AppVeyor x86 build fail

On AppVeyor, all x86 build fail for PHP 8.x.

The error is:

main\streams\plain_wrapper.c(852): error C2220: the following warning is treated as an error
main\streams\plain_wrapper.c(852): warning C4293: '>>': shift count negative or too big, undefined behavior

Full build log: https://ci.appveyor.com/project/macintoshplus/win32service/builds/40440991/job/2a7tmw7fhd36klsd#L306

PHP Source code: https://github.com/php/php-src/blob/00c668a15d699e9a463d7feec9d4f927cb7e4105/main/streams/plain_wrapper.c#L882

Access Denied

Hi, I am getting access denied no matter the method used.

The PHP

PHP Version => 8.0.8

System => Windows NT DESKTOP-QE919S8 10.0 build 19042 (Windows 10) AMD64
Build Date => Jun 29 2021 16:00:22
Build System => Microsoft Windows Server 2019 Datacenter [10.0.17763]
Compiler => Visual C++ 2019
Architecture => x64

The extension

Win32 Service support => enabled
Version => 1.0.0
Current SAPI => cli

Function => State for the current SAPI
win32_start_service_ctrl_dispatcher => enabled
win32_set_service_status => enabled
win32_get_last_control_message => enabled
win32_set_service_exit_mode => enabled
win32_set_service_exit_code => enabled
win32_create_service => enabled
win32_delete_service => enabled
win32_query_service_status => enabled
win32_start_service => enabled
win32_stop_service => enabled
win32_pause_service => enabled
win32_continue_service => enabled
win32_send_custom_control => enabled

What do I need to do to get access. There does not seem to be any information about fixing this.

7.3

On the home page, it states that 7.3 is supported, but when I went to the PECL site, it seems that there is not a 7.3 version out there. Is that going to be updated soon since 7.3 is supposed to be GA tomorrow?

Enable use this extention for all sapi

Remove the cli sapi restriction.

On cli SAPI full work, on other SAPI, 3 functions are disabled with an php error:

image

CLI SAPI PHP Infos:

C:\php\debug>php --ri win32service

win32service

Win32 Service support => enabled
Version => 0.1.3-dev
Current SAPI => cli

Function => State for the current SAPI
win32_start_service_ctrl_dispatcher => enabled
win32_set_service_status => enabled
win32_get_last_control_message => enabled
win32_create_service => enabled
win32_delete_service => enabled
win32_query_service_status => enabled
win32_start_service => enabled
win32_stop_service => enabled
win32_pause_service => enabled
win32_continue_service => enabled

Change version 0.2.0-dev to 0.2.0.beta.1

Hi,

I suggest changing the version from 0.2.0-dev to 0.2.0.beta.1
Reasons:

  1. The "dev" state is a state for continuously changing code.
  2. There are no changes in the code, except corrections of errors.
  3. There are no new features to implement.
  4. It is necessary to test the current code, situation commonly associated with the "beta" phase.

That's why I propose the change to "beta".
The numbering 0.2.0.beta.1 can be modified consistently as needed (0.2.0.beta.2, for example)

Build test for PHP-7.2 (alpha)

Hello, I have tried to build win32service for PHP-7.2 (alpha) and everything points to the extension being prepared for the next PHP branch.

I have created a branch for the tests and adjustments (compiled with VC15): php7.2

0.4.2 required for 7.4 - but labeled as "not for production"

With the public release of PHP 7.4 having been backleveled to the previous VC version, the win32service "release" 0.4.1 is NOT compatible with PHP 7.4.

PHP will fail to start with message
"PHP Warning: PHP Startup: Unable to load dynamic library 'win32service' (tried: C:\Program Files\PHP\v7.4\ext\php_win32service.dll (The specified procedure could not be found.)

Your development version 0.4.2 is compatible and will work with the PHP 7.4 public release - but the project page instructs to "not use for production".

Usage of win32_set_service_exit_code and win32_set_service_exit_mode

I have the following PHP code in my service:

win32_set_service_exit_code( 1 );       // Only used for non-graceful shutdown.
win32_set_service_exit_mode( false );  // Graceful = FALSE; should trigger service recovery.

I expected the service to shutdown "harshly", causing Windows to follow the service's recovery settings.

Instead, the service created Application Event Log entries:

Application Event Log: Event ID 7024 
    The ... service terminated with the following service-specific error: 
    Incorrect function.
    <EventData>
		<Data Name="param1">(the name of my service)</Data>
		<Data Name="param2">%%1</Data>
		<Binary>41006E006D004D0065006400690061000000</Binary> ("AnmMedia" = the short name of my service) 
    </EventData>

Note the %%1 as param2.

Use ValueError when function argument value is wrong

List of function must be upgraded:
win32_continue_service
win32_create_service
win32_delete_service
win32_pause_service
win32_query_service_status
win32_send_custom_control
win32_set_service_status
win32_start_service_ctrl_dispatcher
win32_start_service
win32_stop_service

	zend_argument_value_error(1, "must be between 0 and %d", INT_MAX);
        RETURN_THROWS();

Rename the branch php-7.0 on v1.2

@Jan-E @alphp I want create a new branch v1.2 from the php-7.0 branch and close the old branch.
This would be more consistent with the reality of the sources. The php-7.0 branch is also built for PHP-7.1.

What do you think ?

Interact with Win32Services in a browser: ServiceAccessDeniedException

I would like to allow users of my intranet set to start/stop a Windows service. It sounds like the Win32Service extension for PHP and this library would make this feasible. When I invoke the process with my own/an admin account it works, but when a regular user browses to the sight I get an exception:

Service : localhost\my_test_service Error : (5) Win32Service\Exception\ServiceAccessDeniedException: Access to service my_test_service is denied

The scripts allow me to interact with the service when used on the command line but no in the browser.
Is this scenario not supported, or do I have to add a specific user as described here https://win32service.mactronique.fr/service_library.html with sdset?

Add support for recovery parameters on create_service

Crash on win32_start_service with php.exe

1- add 'path' => '"' . dirname(PHP_BINARY) . '\\php-win.exe"', at line 15 into sample.php
2- run php sample.exe install
3- run php service_dummy.php

Crash stack:

>	php.exe!main(int argc, char * * argv) Ligne 1358	C
 	[Code externe]	

PHP version:

C:\php\debug>php -v
PHP 7.1.0 (cli) (built: Jan  5 2017 08:55:43) ( NTS MSVC14 (Visual C++ 2015) x64 DEBUG )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies

PHP build command: configure.bat --with-mp=auto --enable-cli --disable-zts --enable-win32service=shared --with-php-build=deps --enable-debug --enable-mbstring --enable-cli-win32

Strange behavior on "pause"

With PHP 7.1 , 64 bit windows 11

win32_pause_service(SERVICE_NAME);

seems ok, but...

I noticed in the services.msc that my service remains "running" !??

In the running loop, the win32_get_last_control_message() always returns WIN32_SERVICE_START_PENDING

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.