hambrook/clitaskrunner
Composer 安装命令:
composer require hambrook/clitaskrunner
包简介
Run a CLI command in the background and get updates via callbacks on events including buffer and line updates. You can subscribe to any writable stream and get callbacks triggered for new lines or on each buffer update.
README 文档
README
Run a CLI command in the background and get updates via callbacks on events including buffer and line updates. You can subscribe to any writable stream and get callbacks triggered for new lines or on each buffer update.
Example
$cmd = "mysqldump -uroot -proot -v dbname | mysql -uroot -proot dbname2"; $CLITR = new \Hambrook\CLITaskRunner\CLITaskRunner($cmd); $CLITR->onLine( "stdErr", function($v) { echo "\nCopying table structure: ".$v }, "/\-\- Retrieving table.*? ([^ ]+)\.\.\./" ); $CLITR->onLine( "stdErr", function() { echo "\nCopying table rows..." }, "/\-\- Retrieving rows/" ); $CLITR->process();
Who is it for?
Probably mostly CLI application developers, but there will be usecases I haven't thought of.
Why use this?
I built this because I use mysqldump and rsync from within a CLI application and wanted to customise the output from those commands. It couldn't be done with a simple popen because mysqldump puts its verbose output into the stdErr stream instead of stdOut. Then, naturally, I made it as versatile as possible.
When you could use this?
When you need to run a CLI command and be notified when specific output occurs on a particular stream.
What is this not?
This library sits between your software and CLI commands that it runs. It does not sit between your software and the user. It doesn't do any user input management, argument management, output formatting, or anything of the sort. It helps your software get updates from long-ish running CLI commands.
Functions
__construct()
CLITaskRunner __construct(string $command)
Create a new instance with a command ready to run
onLine()
bool onLine(string $stream, callable $callback, [bool|string $pattern=false])
Add a callback for when a new line is received, with optional regex pattern.
onBuffer()
bool onBuffer(string $stream, callable $callback, [bool|string $pattern=false])
Add a callback for when the buffer is received, with optional regex pattern.
onSuccess()
bool onSuccess(callable $callback)
Add a callback for when the command succeeds.
onFailure()
bool onFailure(callable $callback)
Add a callback for when the command fails.
onComplete()
bool onComplete(callable $callback)
Add a callback for when the process is complete. Gets called after onSuccess and onFailure.
bufferSize()
bool|int bufferSize([int $bufferSize=10])
Gets or sets the buffer size. Buffer size is currently common across all streams.
streams()
bool streams([array $streams=[]])
Get or set the array of streams. Each stream will use its array key as the stream key when adding callbacks.
Testing
Tests coming soon.
Feedback
Tell me if you loved it. Tell me if you hated it. Tell me if you used it and thought "meh". I'm keen to hear your feedback.
Contributing
Feel free to fork this project and submit pull requests, or even just request features via the issue tracker. Please be descriptive with pull requests and match the existing code style.
Roadmap
- Add support for pushing to the stdIn stream
- Add type hinting for all functions
- Add documentation
- Add more examples
- Add more unit tests
- Add any other standard documentation that should be included
- If you have an idea, let me know.
License
Copyright © 2015 Rick Hambrook
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
hambrook/clitaskrunner 适用场景与选型建议
hambrook/clitaskrunner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 3, 最近一次更新时间为 2015 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「cli」 「callback」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hambrook/clitaskrunner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hambrook/clitaskrunner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hambrook/clitaskrunner 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Show a cli spinner while executing a callback
Pleasantly work with asynchronous code.
Swoole request callback for PSR compliant handlers.
SberBank CallbackNotification handler
Extension of php-callback format
Slim starter / Slim skeleton package to boost your development with Slim framework
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2015-10-19