moonspot/supervisor
Composer 安装命令:
composer require moonspot/supervisor
包简介
Supervises forked processes
README 文档
README
The Supervisor class will manage child process by taking a callback to be called after the child is forked. It will restart new children to replace ones that exit.
Why?
Supervisor is useful for any application that needs to have long running PHP processes.
Modern application development sometimes requires running long running PHP processes. Because Supervisor is PHP, it allows you to fork and manage processes that run existing PHP code without any modification.
One such case is managing Gearman workers. In fact, this project was inspired by how GearmanManager manages workers. The plan is to make it the code that handles the process management in future versions of GearmanManager.
Example
<?php // Some Worker Class class SomeWorker { public $keepWorking = true; public function doWork() { while($this->keepWorking) { // do stuff usleep(500000); } } }
<?php require __DIR__."/../../src/Supervisor.php"; require __DIR__."/SomeWorker.php"; use \Moonspot\Supervisor\Supervisor; class MyApplication { protected $super; protected $worker; public function __construct() { $this->super = new Supervisor( array($this, "monitor"), array($this, "log"), array($this, "handleSignal") ); } public function startWorkers($count) { for($x=0; $x<$count; $x++){ $this->super->addChild( array($this, "startWorker"), array(), 3600000 ); } $this->super->wait(); } public function startWorker() { $this->worker = new SomeWorker(); $this->worker->doWork(); } public function handleSignal($signal) { $this->worker->keepWorking = false; } public function monitor() { // we could call $this->super->stop() or $this->super->restart() here } public function log($log) { list($sec, $ms) = explode(".", number_format(microtime(true), 3)); echo "[".date("Y-m-d H:i:s").".$ms] $log\n"; } }
<?php require __DIR__."/MyApplication.php"; $app = new MyApplication(); $app->startWorkers(10);
moonspot/supervisor 适用场景与选型建议
moonspot/supervisor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「threads」 「fork」 「supervisor」 「pcntl_fork」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 moonspot/supervisor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moonspot/supervisor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 moonspot/supervisor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony 3/4/5 bundle which allows you to use @Supervisor annotations to configure how Supervisor runs your console commands.
PHP Trello API Wrapper (fork for php7+) from https://github.com/ashwinks/Trello-API-PHP-Wrapper
A fluent PHP library for supervised master-child process control using pcntl and pipes
Swoole server process management
Library that let you catch fatal errors
This Bundle provides threaded comment functionality for Symfony applications
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-03-14