项目作者: win32service

项目描述 :
The bundle for use Service-Library and Win32Service PHP ext into a Symfony Project.
高级语言: PHP
项目地址: git://github.com/win32service/Win32ServiceBundle.git
创建时间: 2019-02-19T13:49:10Z
项目社区:https://github.com/win32service/Win32ServiceBundle

开源协议:MIT License

下载


Win32ServiceBundle

The bundle for use Service-Library and Win32Service PHP ext into a Symfony Project.

Install

  1. composer require win32service/win32servicebundle

Configure

Add file config/win32service.yaml with this content:

  1. win32_service:
  2. windows_local_encoding: ISO-8859-15 # The windows local encoding for convert the string UTF-8 from configuration to the local encoding.
  3. logging_extra: # This configuration enable a processor for Monolog
  4. enable: false # Enable a processor for add the thread number into the extra fields
  5. channels: # The list of channels whom the processor add the thread number. If empty, the thread number is added for all channels.
  6. - ref1
  7. services:
  8. # Prototype
  9. -
  10. service_id: "" # The service id. If `thread_count` > 1, you can use `%d` to define the place of the thread number
  11. machine: "" # the machine name for this service.
  12. displayed_name: "" # The friendly name of the service. If `thread_count` > 1, you can use `%d` to define the place of the thread number
  13. script_path: ~ # the script name. If not defined, the integrated execute command is used.
  14. script_params: "" # the arguments for the script. if `thread_count` > 1, you can use `%d` to define the place of the thread number
  15. run_max: 1000 # number of loop before exit
  16. thread_count: 1 # the number of this service need to register. Use `%d` into `service_id`, `displayed_name` and `script_params` for contains the service number.
  17. description: "" # the service description
  18. delayed_start: false # If true the starting for the service is delayed
  19. exit: # Settings for the exit mode
  20. graceful: true # if false, the exit fire the recovery action
  21. code: 0 # If graceful is true, this value must not be 0
  22. user: # The User set on the service
  23. account: ~ # the account name
  24. password: ~ # the password
  25. recovery:
  26. enable: false # The recovery action is disabled
  27. delay: 60000 # The delay before run action (in millisecond)
  28. action1: 0 # The action for the first fail
  29. action2: 0 # The action for the second fail
  30. action3: 0 # The action for the next fail
  31. reboot_msg: "" # The message send to log if action is reboot the server
  32. command: "" # The command to be execute if the action is 'run command'
  33. reset_period: 86400 # The period before reset the fail count (in minutes)
  34. dependencies: # The list of service depends
  35. - Netman # An example of dependency.
  36. messenger: # This configuration allow to set on Windows service the Symfony Messenger Consumer.
  37. # Prototype
  38. -
  39. user: # The User set on the service
  40. account: ~ # the account name
  41. password: ~ # the password
  42. receivers: [] # Symfony Messenger transport consumed by the service
  43. machine: '' # the machine name for this service.
  44. displayed_name: ~ # Required, The friendly name of the service. If `thread_count` > 1, you can use `%d` to define the place of the thread number
  45. description: '' # the service description
  46. thread_count: 1 # the number of this service need to register. Use `%d` into `service_id`, `displayed_name` and `script_params` for contains the service number.
  47. delayed_start: false # If true the starting for the service is delayed
  48. limit: 0 # Reboot service after processed X messages
  49. failure-limit: 0 # Reboot service after X messages failure
  50. time-limit: 0 # Reboot service after X seconds

Define the runner

For each service, add a sub-class of Win32Service\Model\AbstractServiceRunner.
The sub-class must be configured in service with the tag win32service.runner with an alias name corresponding to the service_id.

Exemple with one thread

Extension configuration:

  1. win32_service:
  2. windows_local_encoding: ISO-8859-1
  3. services:
  4. -
  5. service_id: "my_service"
  6. displayed_name: "My beautiful service"
  7. #[...]

Sub-class:

  1. class MyRunner extends \Win32Service\Model\AbstractServiceRunner
  2. {}

Service configuration :

  1. services:
  2. MyRunner:
  3. tags:
  4. - { name: win32service.runner, alias: 'my_service'}

Exemple with many thread

Extension configuration:

  1. win32_service:
  2. windows_local_encoding: ISO-8859-1
  3. services:
  4. -
  5. service_id: "my_service_%d"
  6. displayed_name: "My beautiful service"
  7. thread_count: 3
  8. #[...]

Sub-class:

  1. class MyRunner extends \Win32Service\Model\AbstractServiceRunner
  2. {}

Service configuration :

  1. services:
  2. MyRunner:
  3. tags:
  4. - { name: win32service.runner, alias: 'my_service_%d'}

Manage the service

Open an administrator cmd window and go to your project.

Register the service

For register all service, run this command:

  1. php bin\console win32service:register

For register only one service (without thread number) run:

  1. php bin\console win32service:register --service-name=my_service

For register only one service (with thread number) run:

  1. php bin\console win32service:register --service-name=my_service_%d

Unregister the service

For unregister all service, run this command:

  1. php bin\console win32service:unregister

For unregister only one service (without thread number) run:

  1. php bin\console win32service:unregister --service-name=my_service

For unregister only one service (with thread number) run:

  1. php bin\console win32service:unregister --service-name=my_service_%d

Sent action at your services

This command start all service (and all thread) defined in your project.

  1. php bin\console win32service:action start

For sent the action for one service and all thread:

  1. php bin\console win32service:action start --service-name=my_service_%d

For sent the action for one thread of one service (work same if the service has only one thread):

  1. php bin\console win32service:action start --service-name=my_service_1