On my Machine (Win XP SP2) the function "win32_get_last_control_message" never returns 4 so i will have to reply to 0 also.
finally after mixing several examples i now have a version working woithout filling my event log with errors:
<?php
function Service_Main()
{
sleep(1); }
$SERVICE_NAME = "phptestservice";
$SERVICE_DISPLAY = "Test Service with PHP";
$SERVICE_PATH_PARTS = pathinfo(__FILE__);
$SERVICE_PARAMS = " run";
if (!isset($argv[1]))
{
die("this application need to be installed as a service.\n run with param install");
}
if ($argv[1] == 'install')
{
$x = win32_create_service(array(
'service' => $SERVICE_NAME,
'display' => $SERVICE_DISPLAY,
'params' => __FILE__ . $SERVICE_PARAMS,
));
debug_zval_dump($x);
exit;
}
else if ($argv[1] == 'uninstall')
{
$x = win32_delete_service('dummyphp');
debug_zval_dump($x);
exit;
}
else if ($argv[1] != 'run')
{
die("bogus args, needs to run as service");
}
if (!win32_start_service_ctrl_dispatcher($SERVICE_NAME)) die('Could not connect to service :'.$SERVICE_NAME);
win32_set_service_status(WIN32_SERVICE_RUNNING);
while (1)
{
NTServiceResponder();
Service_Main();
sleep(1); }
win32_set_service_status(WIN32_SERVICE_STOPPED);
function NTServiceResponder()
{
switch (win32_get_last_control_message())
{
case 0: win32_set_service_status(WIN32_SERVICE_RUNNING);
return TRUE;
break;
case WIN32_SERVICE_CONTROL_CONTINUE:
return TRUE; case WIN32_SERVICE_CONTROL_INTERROGATE:
win32_set_service_status(WIN32_SERVICE_RUNNING);
return TRUE; case WIN32_SERVICE_CONTROL_STOP:
win32_set_service_status(WIN32_SERVICE_STOPPED);
exit; default:
win32_set_service_status(WIN32_ERROR_CALL_NOT_IMPLEMENTED); }
return FALSE;
}
?>