Recently, I've been updating a PHP extension to allow PHP scripts to run as a Windows Service. I wasn't the initial author, but I've been adding some facilities that I have been wanting.
Documentation : http://docs.php.net/manual/en/book.win32service.php
PECL Package : http://pecl.php.net/package/win32service
SVN Repository : http://svn.php.net/viewvc/pecl/win32service/trunk/
You can install/uninstall/start/st
ontinue the service from the command line as well as the normal Windows Services Management Console.
As the service is running the scripting engine, the scripting engine is greedy in its processor utilisation. That's perfectly normal for conventional execution (CLI, FastCGI, ISAPI, etc.).
In this instance, I'd like to allow assign a priority so that the service doesn't hog all the processor. Essentially, making it a real background task.
The setting needs to be configurable (but not dynamic). So, by using the win32_create_service() call, I want to allow the end-user to assign the priority that they want the script to run at (by default, I'd like it to be IDLE).
Getting the value into the code is easy enough, but I need to be able to hold it prior to the execution of the service. I assume this has to be the registry. If so, is accessing the registry for a windows service particularly easy? Do I just work it out myself?
Once saved, reading the registry during the service_main should be fairly simple, but this would then be within the PHP engine itself. It is at that stage that I need to alter the priority.
This is the main part I'm stuck with.
I've googled altering a running processes priority, external to the process, but not how to alter THIS process.
I'm using MS VC++ 2008 Express Edition (VC9) with SDK6.1 on a Windows 2003 Server virtual machine. The code is built to run on XP x86 and is deployed on Windows XP SP3, Windows 2003 Server and in the next few weeks, a 2008 server (Vista/2008 have additional features for services).