lesser-evil/shell-verbosity-is-evil
Composer 安装命令:
composer require lesser-evil/shell-verbosity-is-evil
包简介
README 文档
README
The SHELL_VERBOSITY environment variable was introduced in symfony/console 3.4 and still appears in symfony/console 6.2. It defines a gooey,
sticky form of verbosity.
The theory seems to be: if you call a command in verbose mode (-v), and if it calls any subcommands, then all those subcommands should also run in
verbose mode. I suppose this is OK if the various commands follow simple, sequential procedures with outputs shown to a human.
But this convention is actively harmful when programs are composed in Unix-style. For simplicity, consider a Symfony Console command (snafu)
which invokes a subcommand:
class SnafuCommand extends Command { public function execute(...) { shell_exec('find_data | filter_data > /tmp/my_data.json'); $data = json_decode(file_get_contents('/tmp/my_data.json')); } }
If you call snafu -v, then Symfony surrepetitiously sets SHELL_VERBOSITY=1 and propagates it to each subprocess. So filter_data receives
SHELL_VERBOSITY=1 and begins outputting a processing log -- in addition to its regular JSON output. Now, the file /tmp/my_data.json is no longer
JSON -- it is JSON plus random noise. So anything reading my_data.json will break.
The overall effect is to make the system flaky. Any Symfony-based command can cause this problem (by setting SHELL_VERBOSITY) or become broken by
it (by accepting SHELL_VERBOSITY). If something breaks, you have to trawl the process-graph to find the two parties to the breakage. The breakage
only happens when running snafu -v. If you run commands individually, or if you run snafu normally, then it works -- which will confound
debugging efforts.
Of course, the reason to use -v is to debug something. If -v itself causes another bug, then you're investigating the combined behavior of two bugs.
How to remove SHELL_VERBOSITY
Friends don't let friends use SHELL_VERBOSITY. This repo defines an adapter to kill SHELL_VERBOSITY.
composer require lesser-evil/shell-verbosity-is-evil
In Symfony 3.4 - 6.2, the SHELL_VERBOSITY behavior is defined by Application::configureIO(). Override this:
use LesserEvil\ShellVerbosityIsEvil; class MyApplication extends Application { protected function configureIO(InputInterface $input, OutputInterface $output) { ShellVerbosityIsEvil::doWithoutEvil(function() use ($input, $output) { parent::configureIO($input, $output); }); } }
lesser-evil/shell-verbosity-is-evil 适用场景与选型建议
lesser-evil/shell-verbosity-is-evil 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 99.5k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 11 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 lesser-evil/shell-verbosity-is-evil 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lesser-evil/shell-verbosity-is-evil 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 99.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-02