note 100333 added to function.win32-create-service
| From: | Anonymous at osu1 dot php dot net | Date: | Fri, 08 Oct 2010 17:05:55 +0000 |
| Subject: | note 100333 added to function.win32-create-service | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173084@lists.php.net to get a copy of this message | ||
<?php
//No timeouts, Flush Content immediatly
set_time_limit(0);
ob_implicit_flush();
//Service Settings
$phpPath = "D:\\php\\php5.2.9";
$ServiceName = 'phpServiceName';
$ServiceDisplay = 'phpDisplayName';
//Windows Service Control
$ServiceAction = "status";
//$ServiceAction = "debug";
if ( isset($_GET['ServiceAction']) and strlen($_GET['ServiceAction']) ) {
$ServiceAction = addslashes($_GET['ServiceAction']);
} else if ( isset($argv) and isset($argv[1]) and strlen($argv[1]) ) {
$ServiceAction = $argv[1];
}
if( $ServiceAction == "status" ) {
$ServiceStatus = win32_query_service_status($ServiceName);
if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_STOPPED ) {
echo "Service Stopped\n\n";
} else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_START_PENDING ) {
echo "Service Start Pending\n\n";
} else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_STOP_PENDING ) {
echo "Service Stop Pending\n\n";
} else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_RUNNING ) {
echo "Service Running\n\n";
} else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_CONTINUE_PENDING ) {
echo "Service Continue Pending\n\n";
} else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_PAUSE_PENDING ) {
echo "Service Pause Pending\n\n";
} else if ( $ServiceStatus['CurrentState'] == WIN32_SERVICE_PAUSED ) {
echo "Service Paused\n\n";
} else{
echo "Service Unknown\n\n";
}
exit;
} else if ( $ServiceAction == "install" ) {
//Install Windows Service
win32_create_service( Array(
'service' => $ServiceName,
'display' => $ServiceDisplay,
'params' => __FILE__ . " run",
'path' => $phpPath."\\php.exe",
));
echo "Service Installed\n\n";
exit;
} else if ( $ServiceAction == "uninstall" ) {
//Remove Windows Service
win32_delete_service($ServiceName);
echo "Service Removed\n\n";
exit;
} else if( $ServiceAction == "start") {
//Start Windows Service
win32_start_service($ServiceName);
echo "Service Started\n\n";
exit;
} else if( $ServiceAction == "stop" ) {
//Stop Windows Service
win32_stop_service($ServiceName);
echo "Service Stopped\n\n";
exit;
} else if ( $ServiceAction == "run" ) {
//Run Windows Service
win32_start_service_ctrl_dispatcher($ServiceName);
win32_set_service_status(WIN32_SERVICE_RUNNING);
} else if ( $ServiceAction == "debug" ) {
//Debug Windows Service
set_time_limit(10);
} else {
exit();
}
//Server Loop
while (1) {
//Handle Windows Service Request
usleep(100*1000);
if ( $ServiceAction == "run" ) {
switch ( win32_get_last_control_message() ) {
case WIN32_SERVICE_CONTROL_CONTINUE:
break;
case WIN32_SERVICE_CONTROL_INTERROGATE:
win32_set_service_status(WIN32_NO_ERROR);
break;
case WIN32_SERVICE_CONTROL_STOP:
win32_set_service_status(WIN32_SERVICE_STOPPED);
exit;
default:
win32_set_service_status(WIN32_ERROR_CALL_NOT_IMPLEMENTED);
}
}
//User Loop
sleep(1);
echo "\n<BR>YOUR CODE HERE";
}
//Exit
if ( $ServiceAction == "run" ) {
win32_set_service_status(WIN32_SERVICE_STOPPED);
}
exit();
----
Server IP: 69.147.83.197
Probable Submitter: 201.6.1.11
----
Manual Page -- http://www.php.net/manual/en/function.win32-create-service.php
Edit -- https://master.php.net/note/edit/100333
Del: integrated -- https://master.php.net/note/delete/100333/integrated
Del: useless -- https://master.php.net/note/delete/100333/useless
Del: bad code -- https://master.php.net/note/delete/100333/bad+code
Del: spam -- https://master.php.net/note/delete/100333/spam
Del: non-english -- https://master.php.net/note/delete/100333/non-english
Del: in docs -- https://master.php.net/note/delete/100333/in+docs
Del: other reasons-- https://master.php.net/note/delete/100333
Reject -- https://master.php.net/note/reject/100333
Search -- https://master.php.net/manage/user-notes.php