Download the PHP package tourze/workerman-process-worker without Composer
On this page you can find all versions of the php package tourze/workerman-process-worker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tourze/workerman-process-worker
More information about tourze/workerman-process-worker
Files in tourze/workerman-process-worker
Package workerman-process-worker
Short Description Workerman 进程管理器,支持外部进程的监控和事件处理
License MIT
Informations about the package workerman-process-worker
Workerman Process Worker
中文
A Workerman extension that allows you to run and monitor external processes within the Workerman environment. This package provides seamless integration with external commands while maintaining the event-driven architecture of Workerman.
Inspired by https://github.com/workbunny
Table of Contents
- Features
- Requirements
- Installation
- Quick Start
- Basic Usage
- Using Event Listeners (Recommended)
- Detailed Usage
- Constructor Parameters
- Event Types
- Event Handling Methods
- Custom Process Handler
- Worker Configuration
- Advanced Example
- API Reference
- ProcessWorker Class
- Events
- ProcessHandlerInterface
- Use Cases
- Contributing
- License
Features
- Process Management: Run any external command as a Workerman process
- Real-time Monitoring: Monitor process output in real-time with event-driven architecture
- Event System: Built-in Symfony EventDispatcher for flexible event handling
- Lifecycle Management: Handle process start, output, and exit events
- Custom Handlers: Support for custom process handlers via
ProcessHandlerInterface - Seamless Integration: Easy integration with existing Workerman applications
- Reload Support: Full support for Workerman's reload functionality
- Dual Event API: Both callback and event listener approaches supported
Requirements
- PHP 8.1 or higher
- Workerman 5.1 or higher
- Symfony EventDispatcher 7.3 or higher
Installation
Install the package via Composer:
Quick Start
Basic Usage
Using Event Listeners (Recommended)
Detailed Usage
Constructor Parameters
The ProcessWorker constructor accepts the following parameters:
$runCommand: The command to execute$processHandler: Optional custom process handler (defaults toDefaultProcessHandler)$eventDispatcher: Optional custom event dispatcher (defaults to newEventDispatcher)
Event Types
The package provides three main events:
- ProcessStartEvent: Triggered when the process starts
- ProcessOutputEvent: Triggered when the process outputs data
- ProcessExitEvent: Triggered when the process terminates
Event Handling Methods
1. Callback Properties (Legacy)
2. Event Listeners (Recommended)
Custom Process Handler
You can implement your own process handler by implementing the ProcessHandlerInterface:
Worker Configuration
Since ProcessWorker extends Workerman's Worker class, you can configure it like any other Worker:
Advanced Example
API Reference
ProcessWorker Class
Constructor
Properties
$onProcessStart: Callback for process start event$onProcessOutput: Callback for process output event$onProcessExit: Callback for process exit event
Methods
getProcessHandler(): ProcessHandlerInterface- Get the process handlergetEventDispatcher(): EventDispatcherInterface- Get the event dispatcheraddListener(string $eventName, callable $listener, int $priority = 0): void- Add event listenergetRunCommand(): string- Get the command being executed
Events
ProcessStartEvent
- Event Name:
process.start - Methods:
getWorker(): ProcessWorker
ProcessOutputEvent
- Event Name:
process.output - Methods:
getWorker(): ProcessWorker,getOutput(): string
ProcessExitEvent
- Event Name:
process.exit - Methods:
getWorker(): ProcessWorker
ProcessHandlerInterface
Required methods for custom process handlers:
Use Cases
- Log Monitoring: Monitor application or system logs in real-time
- Background Tasks: Run background processes with output monitoring
- System Commands: Execute system commands with event-based handling
- Process Orchestration: Coordinate multiple external processes
- Data Processing: Stream data processing with external tools
Contributing
We welcome contributions! Please feel free to submit pull requests or create issues to improve this package.
Development Setup
- Clone the repository
- Install dependencies:
composer install - Run tests:
./vendor/bin/phpunit - Run static analysis:
./vendor/bin/phpstan analyse
License
The MIT License (MIT). Please see License File for more information.
All versions of workerman-process-worker with dependencies
symfony/event-dispatcher-contracts Version ^3
workerman/workerman Version ^5.1