maximgrynykha/winkill
Composer 安装命令:
composer require maximgrynykha/winkill
包简介
Scan & Kill Windows processes in PHP
README 文档
README
Winkill
Work with processes as objects. Find specific ones by attributes and kill them.
⚙️ Installation
To install this library - run the command below in your terminal:
composer require maximgrynykha/winkill
Usage
<?php use Winkill\Winkill; require_once 'vendor/autoload.php'; try { $winkill = new Winkill(); $processes = $winkill->scan();
// Get scanned processes $scanned = $processes->get(); dd($scanned);
// Select specific process(es) $selected = $processes->where( attribute: 'process_name', compareAs: '=', value: 'phpstorm64.exe' )->get(); dd($selected);
// Kill specific process(es) $killed = $processes->where( attribute: 'process_id', compareAs: '=', value: 11492 )->kill(); // Note: If the processes have been killed or not found // by the where-condition then returns an empty array. dd($killed);
} catch (\Winkill\Kernel\Interface\Exception|\Throwable $throwable) { die($throwable->getMessage()); }
API (based on 'tasklist' command)
| Attribute name | Attribute value | Example | Compare operator |
|---|---|---|---|
process_name |
[string]: name with ext | chrome.exe | [string]: =, != |
| [string]: name | chrome | [string]: =, != |
|
| [string]: ext | .exe | [string]: =, != |
|
process_id |
[int]: number of the ID | [string]: =, != |
|
session_name |
[string]: Console / Services | [string]: =, != |
|
session_number |
[int]: number in range of {0-1} | [string]: =, != |
|
consumed_memory |
[int]: number in Kb (kilobytes) | [string]: >, <, =, >=, <=, != |
Select processes
$processes->where('process_name', '=', 'chrome')->get(); $processes->where('process_id', '=', 11455)->get(); $processes->where('session_name', '=', 'console')->get(); $processes->where('session_number', '=', 1)->get(); // ⚠️ Note: consumed memory is estimated in Kb(kilobytes) $processes->where('consumed_memory', '=', 128920)->get();
Terminate processes
$processes->where('process_name', '=', 'chrome')->kill(); $processes->where('process_id', '=', 11455)->kill(); //❗Alert: killing process(es) by attribute [session_name] // may break you 🤯 and/or your computer 💥. Use it only // if you are 100% confident at the ending result. $processes->where('session_name', '=', 'console')->kill(); //❗Alert: killing process(es) by attribute [session_number] // is the same danger as was said previously about attribute // [session_name], so be warned about using it at your risk. $processes->where('session_number', '=', 1)->kill(); // ⚠️ Note: consumed memory is estimated in Kb(kilobytes) $processes->where('consumed_memory', '=', 128920)->kill();
🧱 Snippets
// Terminate processes by an array of process names (all names are an example) array_walk($processes_names = ['chrome', 'firefox', 'slack'], static fn(string $process_name): Process => $processes->where('process_name', '=', $process_name)->kill(), ); // Terminate processes by an array of process ids (all ids are an example) array_walk($processes_ids = [1000, 5595, 17820], static fn(string $process_id): Process => $processes->where('process_id', '=', $process_id)->kill(), ); // You can switch between array_walk and array_map for your needs. // [Confusing in difference?](https://stackoverflow.com/a/3432266/11591375)
$processes = $processes->where('consumed_memory', '<', 1000)->get(); // Sort processes on consumed memory by ASC usort($processes, static fn(Process $process, Process $_process): int => $process->consumed_memory <=> $_process->consumed_memory ); // Sort processes on consumed memory by DESC usort($processes, static fn(Process $process, Process $_process): int => $_process->consumed_memory <=> $process->consumed_memory );
📝 Footnotes
The project utilizes DRY and SOLID principles. Used Design Patterns are listed below.
| Creational | Structural | Behavioral | Others* |
|---|---|---|---|
Abstract Factory |
Facade |
Strategy |
Composition Root |
Factory Method |
Proxy |
Command |
|
Builder |
🤝 Contributing
If you have a problem that cannot be solved using this library, please write your solution, and if you want to help other developers who also use this library (or if you want to keep your solution working after a new version is released, which will be in the package manager dependencies) — create a pull-request. I will be happy to add your excellent code to the library!
🐞 Report any bugs or issues you find on the GitHub issues.
📃 License
The MIT License (MIT). Please see License File for more information.
maximgrynykha/winkill 适用场景与选型建议
maximgrynykha/winkill 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「process」 「windows」 「os」 「operating system」 「processes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maximgrynykha/winkill 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maximgrynykha/winkill 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maximgrynykha/winkill 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
Doctrine implementation of the MetaborStd (Statemachine) for PHP 8.2+
Shell command module for PHP.
Swoole server process management
Inbox pattern process implementation for your Laravel Applications
Laravel package for the simplification and integration of many of your users most wanted login providers. Installation is a breeze. Never worry about OAuth again.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-08