An example of how it should be done:
<?php
class TestClass {
private $args;
function __construct($arg) {
$this->args = $arg;
$this->run();
}
private function run() {
if ($this->args == 'run') {
win32_start_service_ctrl_dispatcher('test_service');
while (WIN32_SERVICE_CONTROL_STOP != win32_get_last_control_message()) {
# do your work here.
# try not to take up more than 30 seconds before going around the loop
# again
}
}
}
}
$object = new TestClass($argv[1]);
?>
win32service 関数
目次
- win32_continue_service — 中断したサービスを再開する
- win32_create_service — SCM データベースに新しいサービスのエントリを作成する
- win32_delete_service — SCM データベースからサービスのエントリを削除する
- win32_get_last_control_message — サービスに送信された直近の制御メッセージを返す
- win32_pause_service — サービスを中断する
- win32_query_service_status — サービスの状態を問い合わせる
- win32_set_service_status — サービスの状態を更新する
- win32_start_service_ctrl_dispatcher — スクリプトを SCM に登録し、指定した名前でサービスとして稼動させる ようにする
- win32_start_service — サービスを開始する
- win32_stop_service — サービスを停止する
brian dot ngure at gmail dot com
29-Apr-2010 09:03
me at sylvain tiret besse point fr
20-Nov-2007 05:45
Just to help a little, the service control command must be in the first script called. If you try to type this portion of code in a separate file and include it, the SCM will not get the controls.
example :
- file1.inc :
<?PHP
class MyClass{
function __construct() {
$x = win32_start_service_ctrl_dispatcher('service');
while (WIN32_SERVICE_CONTROL_STOP!=win32_get_last_control_message()){
//your code
}
}
?>
- service.php :
<?PHP
include("file1.inc");
$object = new MyClass();
?>
WON'T WORK !
