https://github.com/tourze/workerman-master-killer
https://github.com/tourze/workerman-master-killer
process-manager workerman
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tourze/workerman-master-killer
- Owner: tourze
- License: mit
- Created: 2025-04-24T07:27:23.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-11-14T10:03:50.000Z (7 months ago)
- Last Synced: 2025-12-14T07:17:01.776Z (6 months ago)
- Topics: process-manager, workerman
- Language: PHP
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Workerman Master Killer
[English](README.md) | [中文](README.zh-CN.md)
[](https://packagist.org/packages/tourze/workerman-master-killer)
[](https://packagist.org/packages/tourze/workerman-master-killer)
[](https://packagist.org/packages/tourze/workerman-master-killer)
[](https://github.com/tourze/workerman-master-killer)
[](https://github.com/tourze/workerman-master-killer/actions)
[](https://codecov.io/gh/tourze/workerman-master-killer)
A utility to safely kill the Workerman master process. Inspired by
[this Workerman forum post](https://www.workerman.net/q/7958).
## Features
- Safe termination of Workerman master process with timeout protection
- Comprehensive logging support with PSR-3 compatible logger
- Graceful shutdown using SIGQUIT signal
- Testable design with protected methods for mocking
- Compatible with Workerman 5.1+
- Useful for force-stopping master process when it cannot exit normally
## Installation
```bash
composer require tourze/workerman-master-killer
```
## Requirements
- PHP 8.1 or higher
- ext-posix extension
- ext-pcntl extension
- Workerman 5.1 or higher
- PSR-3 compatible logger
## Quick Start
```php
killMaster(); // This method never returns, will call exit
```
### Signal Handler Example
```php
killMaster();
});
```
## How It Works
1. **Read PID**: Reads the master process PID from `Worker::$pidFile`
2. **Send Signal**: Sends SIGQUIT signal to the master process
3. **Wait & Monitor**: Waits up to 5 seconds for the process to exit
4. **Log Results**: Logs the operation result (success/failure)
5. **Force Exit**: If timeout occurs, forcibly exits the program
The process uses polling to check if the master process is still alive, with a 10ms sleep between checks.
## Advanced Usage
### Custom Timeout Configuration
While the default timeout is 5 seconds, you can create a custom implementation
with different timeout values by extending the class:
```php
time();
while (true) {
if ($this->isMasterProcessAlive($master_pid)) {
$this->handleProcessStillAlive($start_time, $timeout);
continue;
}
$this->handleProcessStopped();
}
}
}
```
### Testing Integration
The class is designed for easy testing with protected methods that can be mocked:
```php