create-bulkhead

为 PHP 8.4 生成 Bulkhead 模式实现,通过基于信号量的并发限制和线程池隔离实现资源隔离,并包含单元测试。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "create-bulkhead":https://skillpi.com/zh/skills/deepskill-321e83752aabf482f6f45d554441e6438ae51c210d6a7bf5668c5922f53e8299。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

为 PHP 8.4 生成 Bulkhead 模式实现,通过基于信号量的并发限制和线程池隔离实现资源隔离,并包含单元测试。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
适合谁
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: create-bulkhead
description: Generates Bulkhead pattern for PHP 8.4. Creates resource isolation with semaphore-based concurrency limiting and thread pool isolation. Includes unit tests.

Bulkhead Pattern Generator

Creates Bulkhead pattern infrastructure for resource isolation and fault containment.

When to Use

Scenario Example
External API calls Limit concurrent requests to payment gateway
Database connections Pool size limiting
CPU-intensive work Limit by CPU cores
Multi-instance Redis-based coordination

Component Characteristics

BulkheadInterface

  • Common interface for all isolation strategies
  • Acquire and release semantics
  • Capacity monitoring

Strategies

  • Semaphore Bulkhead: Limits concurrent executions
  • Thread Pool Bulkhead: Isolates execution with dedicated pool
  • Queue-based Bulkhead: Limits with waiting queue

BulkheadFullException

  • Thrown when bulkhead capacity exhausted
  • Contains bulkhead name and capacity info

Generation Process

Step 1: Generate Core Components

Path: src/Infrastructure/Resilience/Bulkhead/

  1. BulkheadInterface.php — Common interface
  2. BulkheadConfig.php — Configuration value object
  3. BulkheadFullException.php — Exception with capacity info

Step 2: Generate Bulkhead Implementation

Choose based on use case:

  1. SemaphoreBulkhead.php — Local semaphore-based limiting
  2. DistributedSemaphoreBulkhead.php — Redis-based for multi-instance

Step 3: Generate Registry (Optional)

  1. BulkheadRegistry.php — Manages multiple bulkheads

Step 4: Generate Tests

  1. SemaphoreBulkheadTest.php — Bulkhead behavior tests
  2. BulkheadConfigTest.php — Configuration tests

File Placement

Component Path
All Classes src/Infrastructure/Resilience/Bulkhead/
Unit Tests tests/Unit/Infrastructure/Resilience/Bulkhead/

Naming Conventions

Component Pattern Example
Interface BulkheadInterface BulkheadInterface
Semaphore SemaphoreBulkhead SemaphoreBulkhead
Distributed DistributedSemaphoreBulkhead DistributedSemaphoreBulkhead
Config BulkheadConfig BulkheadConfig
Registry BulkheadRegistry BulkheadRegistry
Exception BulkheadFullException BulkheadFullException
Test {ClassName}Test SemaphoreBulkheadTest

Quick Template Reference

BulkheadInterface

interface BulkheadInterface
{
    public function execute(callable $operation): mixed;
    public function tryAcquire(): bool;
    public function release(): void;
    public function getAvailablePermits(): int;
    public function getActiveCount(): int;
    public function getName(): string;
}

BulkheadConfig

final readonly class BulkheadConfig
{
    public function __construct(
        public int $maxConcurrentCalls = 10,
        public int $maxWaitDuration = 0,
        public bool $fairness = true
    ) {}

    public static function default(): self;
    public static function forCpuBound(int $cpuCores): self;
    public static function forIoBound(int $cpuCores): self;
    public static function forExternalService(int $maxConnections): self;
}

Usage Example

// Create limiter
$bulkhead = new SemaphoreBulkhead(
    name: 'payment-gateway',
    config: BulkheadConfig::forExternalService(maxConnections: 20),
    logger: $logger
);

// Execute with isolation
try {
    $result = $bulkhead->execute(fn() => $client->charge($request));
} catch (BulkheadFullException $e) {
    return Result::serviceOverloaded();
}

Use Case Selection

Use Case Bulkhead Type Config
External API calls Semaphore Limited by API rate limits
Database connections Semaphore Limited by pool size
CPU-intensive work Semaphore Limited by CPU cores
Multi-instance Distributed Redis-based coordination
Mixed workloads Registry Per-service configuration

Anti-patterns to Avoid

Anti-pattern Problem Solution
Global Bulkhead Single point of contention Per-service bulkheads
No Release Permit leak Always release in finally
Wrong Size Too small = rejected, too large = no protection Right-size per service
No Metrics Can't monitor usage Track acquired/rejected
Infinite Wait Thread starvation Set maxWaitDuration
No Fallback Hard failure on full Provide degraded response

References

For complete PHP templates and examples, see:

  • references/templates.md — BulkheadInterface, Config, SemaphoreBulkhead, DistributedSemaphoreBulkhead, Registry
  • references/examples.md — PaymentGatewayAdapter, ConnectionPool, OrderService examples and tests

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值85/100

亮点

  • 提供 PHP 8.4 的 Bulkhead 模式生成,解决资源隔离和故障隔离的实际问题
  • 涵盖外部 API 调用、数据库连接、CPU 密集型任务等高频使用场景
  • 包含完整的单元测试,提升代码可靠性
触发精准90/100

亮点

  • description 明确描述功能,触发词完整且边界清晰
  • 详细列出使用场景和组件特性,便于用户理解适用性
结构规范95/100

亮点

  • 结构清晰,分步骤说明生成流程,包含命名规范、模板参考、使用示例
  • frontmatter 完整,文档组织良好,易于理解和执行
执行可靠88/100

亮点

  • 工具来源明确(PHP 8.4),参数说明清晰
  • 涵盖主要异常处理(BulkheadFullException),有使用示例和测试说明
证据可验 (前四项均值)90/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。