Connecting Tech Pros Worldwide Forums | Help | Site Map

win32service Functions

Daniel
Guest
 
Posts: n/a
#1: Oct 28 '05
Does anybody have any practical experience at running PHP scripts as a
Windows service?

I've followed the instructions at
http://www.php.net/manual/en/ref.win32service.php 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.

---begin-code----
<?php
$details['service']='phpmaintenance';
$details['display']='PHP Maintenance';
$details['params']='C:\\Inetpub\\wwwroot\\maintenance\\php_maintenan ce.php
run';
$details['start_type']="WIN32_SERVICE_AUTO_START";
$x = win32_create_service($details);
echo $x;
?>
---end-code----
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 ?

Daniel


Chuck Anderson
Guest
 
Posts: n/a
#2: Oct 28 '05

re: win32service Functions


Daniel wrote:
[color=blue]
>Does anybody have any practical experience at running PHP scripts as a
>Windows service?
>
>I've followed the instructions at
>http://www.php.net/manual/en/ref.win32service.php 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.
>
>
>[/color]
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
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Steve
Guest
 
Posts: n/a
#3: Oct 28 '05

re: win32service Functions


[color=blue]
> I've followed the instructions at
> http://www.php.net/manual/en/ref.win32service.php and have downloaded[/color]

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?

---
Steve

Daniel
Guest
 
Posts: n/a
#4: Oct 28 '05

re: win32service Functions


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

This is the "php_maintenance.php" file.
---begin-code----
<?php
if ($argv[1] == 'run') {
win32_start_service_ctrl_dispatcher('phpmaintenanc e');
$dataoutput="Hello World\r\n";

while (WIN32_SERVICE_CONTROL_STOP != win32_get_last_control_message())
{
$filename="C:\\inetpub\\Test_".date("Ymd_His").".l og";
if ($handle = fopen($filename, 'a')) {
fwrite($handle, $dataoutput);
fclose($handle);
}
sleep(3);
}
}
?>
---end-code----

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
that.

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),
http://snaps.php.net/win32/ 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
Daniel

Daniel
Guest
 
Posts: n/a
#5: Oct 28 '05

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
Daniel

Daniel
Guest
 
Posts: n/a
#6: Nov 10 '05

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
purpose.

Thank you
Daniel

Closed Thread