win32service Functions

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Does anybody have any practical experience at running PHP scripts as a
Windows service?

I've followed the instructions at and have downloaded
the php_win32service.dll file and placed it in my extensions directory,
added the line "extension=php_win32service.dll" to my PHP.ini file,
restarted IIS, and when I run phpinfo() it shows as being enabled. Yet
anytime I attempt to create a service all I get back is the number "5".

Platform: Dell Optiplex GX270, Windows XP Pro w/SP2, IIS, PHP 5.0.5
running as ISAPI, Zend Optimizer v2.5.10.

List of loaded extensions:
[0] => bcmath
[1] => calendar
[2] => com_dotnet
[3] => ctype
[4] => ftp
[5] => iconv
[6] => odbc
[7] => pcre
[8] => session
[9] => SPL
[10] => SQLite
[11] => standard
[12] => tokenizer
[13] => zlib
[14] => libxml
[15] => dom
[16] => SimpleXML
[17] => wddx
[18] => xml
[19] => ISAPI
[20] => mcrypt
[21] => mssql
[22] => mysql
[23] => xsl
[24] => win32service
[25] => Zend Optimizer

This is the code I'm using to try and create the service.

$details['display']='PHP Maintenance';
$x = win32_create_service($details);
echo $x;
No errors or warning are generated.

I'm assuming this should put a service on the list of services when
viewed from the mmc console, but nothing is showing up. I checked
current tasks, nothing matches. I've tried starting it from a command
line as well as via a web browser, yet nothing seems to work.

Anybody have any ideas ?


Re: win32service Functions

Daniel wrote:

Quoted text here. Click to load it
Question. I have been poking around to learn more about this for myself  
and have deduced, but not seen it explicitly mentioned, that this only  
for available Php 5.0. Is that correct, or is there something similar  
for version 4 (4.4)?

 Chuck Anderson • Boulder, CO
 Integrity is obvious.
 The lack of it is common.

Re: win32service Functions

Quoted text here. Click to load it

Did you also modify your service script to execute
win32_start_service_ctrl_dispatcher() and then run in a service loop?

Other than that, my only suggestion is return code 5 means "file not
found" - did you give the right path?


Re: win32service Functions

Full path (copied and pasted from Windows Explorer) is
"C:\Inetpub\wwwroot\maintenance\php_maintenance.php" (looks good from

This is the "php_maintenance.php" file.
if ($argv[1] == 'run') {
        $dataoutput="Hello World\r\n";

    while (WIN32_SERVICE_CONTROL_STOP != win32_get_last_control_message())
        if ($handle = fopen($filename, 'a')) {
            fwrite($handle, $dataoutput);

The idea for this piece of test code is to write a new text file
containing "Hello World" every 3 seconds to C:\Inetpub.
I know PHP has write access to that folder as my error handler puts
it's logs there. I figured if it worked and I saw the new files I would
move forward building a new maintenance system, but it's not even doing

It looks simple enough and I might be missing something simple, I just
can't figure out what. I checked security on the php_win32service.dll
file and it does have read, write, and execute permissions for both the
IUSR and IWAM accounts.

The only new thing that has been added lately was the Zend Optimizer. I
may try uninstalling it and see what happens, otherwise I'm at a loss
to figure out why it will not work.

PS:In answer to the 2nd message, if you check this page (PECL library), it looks like there is not a version of the
dll available under PHP 4.x.x. Somebody may correct me later, and
that's Ok, but I don't see one for PHP 4.x.x.

Thank you

Re: win32service Functions

It dawned on me that IUSR and IWAM accounts probably make no difference
in this case. I did set permissions for "Everyone" in Security to read,
write, and execute. That made no difference.

Is there possibly another file someplace that I might need to change
permissions on?

Thank you

Re: win32service Functions

I finally figured out why it was not working.
PHP is picking up the same php.ini file being used for the website and
that contains an auto_prepend file, and it was running into errors,
thus the service was not getting created.

If I disable the auto_prepend file it works Ok. I just need to create a
separete PHP folder with the executables and a special php.ini for this

Thank you

Site Timeline