Download the PHP package tourze/symfony-workerman-bundle without Composer
On this page you can find all versions of the php package tourze/symfony-workerman-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package symfony-workerman-bundle
symfony-workerman-bundle
中文
Symfony integration bundle for Workerman, a high-performance asynchronous PHP socket framework.
Table of Contents
- Features
- Installation
- Quick Start
- Commands
- Core Concepts
- Advanced Usage
- Architecture Diagram
- Technical Notes
- Dependencies
- Contributing
- License
Features
- Command-line based Workerman service management
- Automatic discovery and registration of Worker services through interfaces
- Support for TCP/UDP and other network protocols
- Buffer management mechanism
- Integrated Crontab scheduling system
- Automatic Worker process optimization based on CPU cores
- Seamless integration with Symfony dependency injection container
Installation
Quick Start
1. Create a Worker Service
2. Create a Timer Task
3. Run the Workerman Service
Commands
workerman:run
The main command to manage Workerman services.
Usage:
Arguments:
action: Required. The action to perform (start|stop|restart|reload|status|connections)
Options:
-d, --daemon: Run in daemon mode (for start action)
Actions:
start: Start all registered Worker servicesstop: Stop all running Worker servicesrestart: Restart all Worker servicesreload: Gracefully reload all Worker servicesstatus: Display the status of all Worker servicesconnections: Display connection information
workerman:tcp
Start a single-process TCP Worker server with Symfony Event integration.
Usage:
Options:
--host: Listen host (default: 127.0.0.1 or env WORKERMAN_TCP_HOST)-p, --port: Listen port (default: 2345 or env WORKERMAN_TCP_PORT)-d, --daemon: Run in daemon mode
Example:
Core Concepts
Interfaces
-
WorkerBuilderInterface: Base interface for Worker services
getName(): Define service identifieronWorkerStart(): Worker startup initializationonWorkerStop(): Worker cleanup logiconWorkerReload(): Worker reload handling
-
ConnectableInterface: Interface for network-connected Workers
getTransport(): Specify transport protocol (tcp/udp)getListenIp()/getListenPort(): Listen configuration- Connection events:
onConnect/onClose/onMessage/onError
-
BufferAwareInterface: Buffer management interface
onBufferFull(): Handle when send buffer is fullonBufferDrain(): Handle when send buffer is drained
- TimerInterface: Timer task interface based on workerman/crontab
getExpression(): Define Cron expressionexecute(): Task execution logic
Service Auto-configuration
Services implementing the above interfaces are automatically tagged:
WorkerBuilderInterface→workerman.workerConnectableInterface→workerman.connectableBufferAwareInterface→workerman.buffer-awareTimerInterface→workerman.timer
TCP Worker Event System
The workerman:tcp command provides a Symfony Event-based TCP server. All Workerman events are converted to Symfony Events for easy integration.
Available Events
TcpWorkerStartEvent: Fired when the Worker startsTcpWorkerStopEvent: Fired when the Worker stopsTcpWorkerConnectEvent: Fired when a client connectsTcpWorkerMessageEvent: Fired when a message is receivedTcpWorkerCloseEvent: Fired when a connection closesTcpWorkerErrorEvent: Fired when an error occurs
Example Event Listener
Configuration
You can configure the TCP Worker using environment variables:
Advanced Usage
Custom Protocol Implementation
You can implement custom protocols by extending the protocol handling:
Advanced Worker Configuration
For complex scenarios, you can customize Worker properties:
Environment-specific Configuration
Use Symfony's environment system for different configurations:
Architecture Diagram
Technical Notes
Requirements
- PHP CLI mode is required
- Use daemon mode in production environments
Multi-process Considerations
- Be aware of concurrent access to shared resources
- Timer tasks execute in each Worker process
- Services should be stateless or ensure state consistency
Performance Optimization
- Worker count is automatically set to CPU core count
- For CPU-intensive tasks: keep Workers = CPU cores
- For IO-intensive tasks: can increase Worker count
- Monitor buffer management to prevent memory overflow
Dependencies
- Core Dependencies:
workerman/workerman: Core async network frameworkworkerman/crontab: Timer task support
- Helper Dependencies:
fidry/cpu-core-counter: CPU core detectionphpinnacle/buffer: Binary data buffer handling
Contributing
Please follow the standard contribution guidelines for this monorepo.
License
This package is part of the tourze monorepo and follows its licensing terms.
All versions of symfony-workerman-bundle with dependencies
fidry/cpu-core-counter Version ^1.2.0
phpinnacle/buffer Version ^1.2.0
symfony/framework-bundle Version ^6.4
workerman/workerman Version ^5.1
workerman/crontab Version ^1.0.7