{"id":33948138,"url":"https://github.com/tourze/workerman-master-killer","last_synced_at":"2026-03-08T23:31:05.913Z","repository":{"id":289626520,"uuid":"971873402","full_name":"tourze/workerman-master-killer","owner":"tourze","description":null,"archived":false,"fork":false,"pushed_at":"2025-11-14T10:03:50.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-14T07:17:01.776Z","etag":null,"topics":["process-manager","workerman"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tourze.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-04-24T07:27:23.000Z","updated_at":"2025-10-31T07:57:56.000Z","dependencies_parsed_at":"2025-04-24T08:34:45.582Z","dependency_job_id":"f1ca4fff-6132-4d8c-a33e-4529cb062b4e","html_url":"https://github.com/tourze/workerman-master-killer","commit_stats":null,"previous_names":["tourze/workerman-master-killer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tourze/workerman-master-killer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tourze%2Fworkerman-master-killer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tourze%2Fworkerman-master-killer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tourze%2Fworkerman-master-killer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tourze%2Fworkerman-master-killer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tourze","download_url":"https://codeload.github.com/tourze/workerman-master-killer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tourze%2Fworkerman-master-killer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30276902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T20:45:49.896Z","status":"ssl_error","status_checked_at":"2026-03-08T20:45:49.525Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["process-manager","workerman"],"created_at":"2025-12-12T18:26:52.012Z","updated_at":"2026-03-08T23:31:05.907Z","avatar_url":"https://github.com/tourze.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Workerman Master Killer\n\n[English](README.md) | [中文](README.zh-CN.md)\n\n[![Latest Version](https://img.shields.io/packagist/v/tourze/workerman-master-killer.svg?style=flat-square)](https://packagist.org/packages/tourze/workerman-master-killer)\n[![PHP Version](https://img.shields.io/packagist/php-v/tourze/workerman-master-killer.svg?style=flat-square)](https://packagist.org/packages/tourze/workerman-master-killer)\n[![Total Downloads](https://img.shields.io/packagist/dt/tourze/workerman-master-killer.svg?style=flat-square)](https://packagist.org/packages/tourze/workerman-master-killer)\n[![License](https://img.shields.io/github/license/tourze/workerman-master-killer.svg?style=flat-square)](https://github.com/tourze/workerman-master-killer)\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/tourze/workerman-master-killer/ci.yml?branch=master\u0026style=flat-square)](https://github.com/tourze/workerman-master-killer/actions)\n[![Coverage Status](https://img.shields.io/codecov/c/github/tourze/workerman-master-killer?style=flat-square)](https://codecov.io/gh/tourze/workerman-master-killer)\n\nA utility to safely kill the Workerman master process. Inspired by \n[this Workerman forum post](https://www.workerman.net/q/7958).\n\n## Features\n\n- Safe termination of Workerman master process with timeout protection\n- Comprehensive logging support with PSR-3 compatible logger\n- Graceful shutdown using SIGQUIT signal\n- Testable design with protected methods for mocking\n- Compatible with Workerman 5.1+\n- Useful for force-stopping master process when it cannot exit normally\n\n## Installation\n\n```bash\ncomposer require tourze/workerman-master-killer\n```\n\n## Requirements\n\n- PHP 8.1 or higher\n- ext-posix extension\n- ext-pcntl extension\n- Workerman 5.1 or higher\n- PSR-3 compatible logger\n\n## Quick Start\n\n```php\n\u003c?php\n\nuse Psr\\Log\\LoggerInterface;\nuse Tourze\\Workerman\\MasterKiller\\MasterKiller;\nuse Workerman\\Worker;\n\n// Set up your Workerman PID file\nWorker::$pidFile = '/path/to/workerman.pid';\n\n// Create a PSR-3 compatible logger\n$logger = new YourLoggerImplementation();\n\n// Create and use the killer\n$killer = new MasterKiller($logger);\n$killer-\u003ekillMaster(); // This method never returns, will call exit\n```\n\n### Signal Handler Example\n\n```php\n\u003c?php\n\nuse Psr\\Log\\LoggerInterface;\nuse Tourze\\Workerman\\MasterKiller\\MasterKiller;\nuse Workerman\\Worker;\n\n// Set up signal handler for graceful shutdown\npcntl_signal(SIGTERM, function() use ($logger) {\n    $killer = new MasterKiller($logger);\n    $killer-\u003ekillMaster();\n});\n```\n\n## How It Works\n\n1. **Read PID**: Reads the master process PID from `Worker::$pidFile`\n2. **Send Signal**: Sends SIGQUIT signal to the master process\n3. **Wait \u0026 Monitor**: Waits up to 5 seconds for the process to exit\n4. **Log Results**: Logs the operation result (success/failure)\n5. **Force Exit**: If timeout occurs, forcibly exits the program\n\nThe process uses polling to check if the master process is still alive, with a 10ms sleep between checks.\n\n## Advanced Usage\n\n### Custom Timeout Configuration\n\nWhile the default timeout is 5 seconds, you can create a custom implementation \nwith different timeout values by extending the class:\n\n```php\n\u003c?php\n\nuse Tourze\\Workerman\\MasterKiller\\MasterKiller;\n\nclass CustomMasterKiller extends MasterKiller\n{\n    protected function waitForProcessStop(int $master_pid): never\n    {\n        $timeout = 10; // Custom 10-second timeout\n        $start_time = $this-\u003etime();\n        \n        while (true) {\n            if ($this-\u003eisMasterProcessAlive($master_pid)) {\n                $this-\u003ehandleProcessStillAlive($start_time, $timeout);\n                continue;\n            }\n            \n            $this-\u003ehandleProcessStopped();\n        }\n    }\n}\n```\n\n### Testing Integration\n\nThe class is designed for easy testing with protected methods that can be mocked:\n\n```php\n\u003c?php\n\nuse PHPUnit\\Framework\\TestCase;\nuse Psr\\Log\\LoggerInterface;\nuse Tourze\\Workerman\\MasterKiller\\MasterKiller;\n\nclass TestableMasterKiller extends MasterKiller\n{\n    public function __construct(LoggerInterface $logger)\n    {\n        parent::__construct($logger);\n    }\n    \n    // Override methods for testing\n    protected function exit(int $status = 0): never\n    {\n        throw new TestExitException($status);\n    }\n}\n```\n\n## API Documentation\n\n### MasterKiller Class\n\n#### Constructor\n\n```php\npublic function __construct(LoggerInterface $logger)\n```\n\nCreates a new MasterKiller instance with the provided PSR-3 logger.\n\n#### Methods\n\n##### killMaster(): never\n\nKills the Workerman master process. This method never returns and will call `exit()`.\n\n**Process:**\n- Reads master PID from `Worker::$pidFile`\n- Sends SIGQUIT signal to master process\n- Waits up to 5 seconds for process to exit\n- Logs operation result\n- Calls `exit(0)` on success or `exit()` on timeout\n\n## Contributing\n\nPlease see [CONTRIBUTING.md](CONTRIBUTING.md) for details.\n\n### Development\n\n```bash\n# Run tests\n./vendor/bin/phpunit\n\n# Run static analysis\n./vendor/bin/phpstan analyse\n\n# Check code style\n./vendor/bin/php-cs-fixer fix --dry-run\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftourze%2Fworkerman-master-killer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftourze%2Fworkerman-master-killer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftourze%2Fworkerman-master-killer/lists"}