win32_create_service

(PECL win32service >=0.1.0)

win32_create_serviceHizmet yönetim veritabanında yeni bir hizmet girdisi oluşturur

Açıklama

win32_create_service(array $ayrıntılar, string $makine = ?): mixed

Hizmet yönetim veritabanında yeni bir hizmet girdisi oluşturur.

Değiştirgeler

ayrıntılar

Hizmet ayrıntıları dizisi:

service

Hizmetin kısa ismi. net komutuyla hizmeti denetlemekte kullanılacak isimdir. İsim eşsiz olmalı (aynı isimde iki hizmet olmamalı) ve mümkünse boşluk karakterleri içermemelidir.

display

Hizmetin görünen ismi. Hizmetler programcığında göreceğiniz isimdir.

user

Hizmetin aidiyetinde çalışacağı kullanıcı hesabı. Belirtilmediği takdirde hizmet LocalSystem hesabı altında çalışır. Bir kullanıcı ismi belirtilirse bir parola da belirtmek gerekir.

password

user anahtarında belirtilen kullanıcının parolası.

path

Hizmet başlatıldığında çalıştırılacak çalıştırılabilirin mutlak dosya yolu. Belirtilmediği takdirde geçerli PHP süreci kullanılır.

params

Hizmet başlatılırken komut satırına aktarılacak değiştirgeler. Bir PHP betiğini hizmet olarak çalıştıracaksanız ilk değiştirge çalıştırılacak PHP betiğinin mutlak yolu olmalıdır. Eğer betik ismi veya dosya yolu boşluk karakteri içeriyorsa PHP betiğindeki dosya yolunun tamamını çift tırnak (") karakterlerinin arasına alın.

load_order

load_order denetimi. Bu henüz tamamen desteklenmiyor.

svc_type

Hizmet türü belirtilir. Belirtilmezse öntanımlı değer: WIN32_SERVICE_WIN32_OWN_PROCESS. Ne yaptığınızdan emin değilseniz bunu değiştirmeyin.

start_type

Hizmetin nasıl başlatılması gerektiği belirtilir. Öntanımlı değer WIN32_SERVICE_AUTO_START olup hizmetin makine başlatıldığında çalıştırılacağı anlamına gelir.

error_control

Hizmet yöneticisinin hizmet ile ilgili bir sorun saptadığında ne yapacağı belirtilir. Öntanımlı değer: WIN32_SERVER_ERROR_IGNORE. Desteklenen tek değer budur.

machine

Hizmeti oluşturmak istediğiniz makinenin ismi; belirtilmesi isteğe bağlıdır. Verilmezse yerel makine ismi kullanılır.

Dönen Değerler

Başarılı olursa true, aksi takdirde bir win32 hata kodu döner.

Örnekler

Örnek 1 - win32_create_service() örneği

'dummyphp' kısa isimli bir hizmet oluşturur.

<?php
$x 
win32_create_service(array(
        
'service' => 'dummyphp',
        
'display' => 'PHP hizmeti denemesi',
        
'params' => __FILE__ ' run',
));
debug_zval_dump($x);
?>

Ayrıca Bakınız

add a note add a note

User Contributed Notes 2 notes

up
2
Anonymous
13 years ago
[An example of how to create a Windows service.  Evaluate code first and use at your own risk!]

<?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();
?>
up
1
pauljamesthomson at gmail dot com
17 years ago
Other start_type values:

0x00000002: A service started automatically by the service control manager during system startup. For more information, see Automatically Starting Services.

0x00000000: A device driver started by the system loader. This value is valid only for driver services.

0x00000003: A service started by the service control manager when a process calls the win32_start_service() function.

0x00000004: A service that cannot be started. Attempts to start the service result in the error code

0x00000001: A device driver started by the IoInitSystem function. This value is valid only for driver services.

I can confirm that 0x00000003 works as expected (service is created, but must be started manually).

More here:

http://msdn2.microsoft.com/en-us/library/ms682450.aspx
To Top