win32service / win32servicebundle
用于将 win32service/service-library 整合到 Symfony 项目的组件包
v2.0.0
2024-07-26 14:14 UTC
Requires
- php: ^8.0
- symfony/config: ^5.4|^6.0
- symfony/console: ^5.4|^6.0
- symfony/dependency-injection: ^5.4|^6.0
- symfony/event-dispatcher: ^5.4|^6.0
- symfony/framework-bundle: ^5.4|^6.0
- symfony/http-kernel: ^5.4|^6.0
- symfony/yaml: ^5.4|^6.0
- win32service/service-library: ^1.0||1.x-dev
Requires (Dev)
- doctrine/doctrine-bundle: ^2.12
- doctrine/doctrine-migrations-bundle: ^3.3
- doctrine/orm: ^2.19
- rector/rector: ^0.14.2
- symfony/dotenv: ^5.4|^6.0
- symfony/messenger: ^5.4|^6.0
- symfony/monolog-bundle: ^3.10
- symfony/runtime: ^5.4|^6.0
Suggests
- ext-win32service: On Windows only, install this extension to run PHP Service on Windows Service Manager
This package is auto-updated.
Last update: 2024-09-26 14:32:32 UTC
README
此组件包用于在 Symfony 项目中使用 Service-Library 和 Win32Service PHP 扩展。
安装
composer require win32service/win32servicebundle
配置
添加文件 config/win32service.yaml
并包含以下内容
win32_service: windows_local_encoding: ISO-8859-15 # The windows local encoding for convert the string UTF-8 from configuration to the local encoding. logging_extra: # This configuration enable a processor for Monolog enable: false # Enable a processor for add the thread number into the extra fields channels: # The list of channels whom the processor add the thread number. If empty, the thread number is added for all channels. - ref1 services: # Prototype - service_id: "" # The service id. If `thread_count` > 1, you can use `%d` to define the place of the thread number machine: "" # the machine name for this service. displayed_name: "" # The friendly name of the service. If `thread_count` > 1, you can use `%d` to define the place of the thread number script_path: ~ # the script name. If not defined, the integrated execute command is used. script_params: "" # the arguments for the script. if `thread_count` > 1, you can use `%d` to define the place of the thread number run_max: 1000 # number of loop before exit 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. description: "" # the service description delayed_start: false # If true the starting for the service is delayed exit: # Settings for the exit mode graceful: true # if false, the exit fire the recovery action code: 0 # If graceful is true, this value must not be 0 user: # The User set on the service account: ~ # the account name password: ~ # the password recovery: enable: false # The recovery action is disabled delay: 60000 # The delay before run action (in millisecond) action1: 0 # The action for the first fail action2: 0 # The action for the second fail action3: 0 # The action for the next fail reboot_msg: "" # The message send to log if action is reboot the server command: "" # The command to be execute if the action is 'run command' reset_period: 86400 # The period before reset the fail count (in minutes) dependencies: # The list of service depends - Netman # An example of dependency. messenger: # This configuration allow to set on Windows service the Symfony Messenger Consumer. # Prototype - user: # The User set on the service account: ~ # the account name password: ~ # the password receivers: [] # Symfony Messenger transport consumed by the service machine: '' # the machine name for this service. 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 description: '' # the service description 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. delayed_start: false # If true the starting for the service is delayed limit: 0 # Reboot service after processed X messages failure-limit: 0 # Reboot service after X messages failure time-limit: 0 # Reboot service after X seconds
定义运行器
对于每个服务,添加一个 Win32Service\Model\AbstractServiceRunner
的子类。子类必须在服务中使用带有别名名称的 win32service.runner
标签进行配置,该别名名称与 service_id
相对应。
单线程示例
扩展配置
win32_service: windows_local_encoding: ISO-8859-1 services: - service_id: "my_service" displayed_name: "My beautiful service" #[...]
子类
class MyRunner extends \Win32Service\Model\AbstractServiceRunner {}
服务配置
services: MyRunner: tags: - { name: win32service.runner, alias: 'my_service'}
多线程示例
扩展配置
win32_service: windows_local_encoding: ISO-8859-1 services: - service_id: "my_service_%d" displayed_name: "My beautiful service" thread_count: 3 #[...]
子类
class MyRunner extends \Win32Service\Model\AbstractServiceRunner {}
服务配置
services: MyRunner: tags: - { name: win32service.runner, alias: 'my_service_%d'}
管理服务
打开管理员命令提示符窗口并转到您的项目目录。
注册服务
要注册所有服务,请运行此命令
php bin\console win32service:register
要仅注册一个服务(不带线程号),请运行
php bin\console win32service:register --service-name=my_service
要仅注册一个服务(带线程号),请运行
php bin\console win32service:register --service-name=my_service_%d
注销服务
要注销所有服务,请运行此命令
php bin\console win32service:unregister
要注销一个服务(不带线程号),请运行
php bin\console win32service:unregister --service-name=my_service
要注销一个服务(带线程号),请运行
php bin\console win32service:unregister --service-name=my_service_%d
向服务发送动作
此命令启动项目中定义的所有服务(及其所有线程)。
php bin\console win32service:action start
为单个服务和所有线程发送动作
php bin\console win32service:action start --service-name=my_service_%d
为单个服务的单个线程发送动作(如果服务只有一个线程,则效果相同)
php bin\console win32service:action start --service-name=my_service_1