From acc
Generates PHP 8.4 timeout pattern components for execution limits in API calls, DB queries, queues, file ops; includes signal/stream executors, PSR-15 middleware, fallbacks, tests.
How this skill is triggered — by the user, by Claude, or both
Slash command
/acc:create-timeoutThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Creates Timeout pattern infrastructure for execution time limits with fallback support.
Creates Timeout pattern infrastructure for execution time limits with fallback support.
| Scenario | Example |
|---|---|
| External API calls | HTTP requests to third-party services |
| Database queries | Long-running or unoptimized queries |
| Queue consumers | Message processing time limits |
| File operations | Large file uploads/downloads |
| Distributed calls | gRPC, SOAP, or REST inter-service calls |
| Batch processing | Individual item timeout within batch |
Determine:
Domain Layer (src/Domain/Shared/Timeout/)
TimeoutConfig.php — Configuration value objectTimeoutInterface.php — Execution contractTimeoutException.php — Timeout exceeded exceptionInfrastructure Layer (src/Infrastructure/Resilience/Timeout/)
SignalTimeoutExecutor.php — pcntl_alarm based implementationStreamTimeoutExecutor.php — stream_set_timeout basedNullTimeoutExecutor.php — No-op for testingTimeoutExecutorFactory.php — Environment-aware factoryPresentation Layer (src/Presentation/Middleware/)
TimeoutMiddleware.php — PSR-15 HTTP middlewareTests
TimeoutConfigTest.phpSignalTimeoutExecutorTest.phpTimeoutExceptionTest.php| Layer | Path |
|---|---|
| Domain Types | src/Domain/Shared/Timeout/ |
| Infrastructure | src/Infrastructure/Resilience/Timeout/ |
| Middleware | src/Presentation/Middleware/ |
| Unit Tests | tests/Unit/{Layer}/{Path}/ |
| Component | Pattern | Example |
|---|---|---|
| Config VO | TimeoutConfig | TimeoutConfig |
| Interface | TimeoutInterface | TimeoutInterface |
| Signal Impl | SignalTimeoutExecutor | SignalTimeoutExecutor |
| Stream Impl | StreamTimeoutExecutor | StreamTimeoutExecutor |
| Null Impl | NullTimeoutExecutor | NullTimeoutExecutor |
| Exception | TimeoutException | TimeoutException |
| Factory | TimeoutExecutorFactory | TimeoutExecutorFactory |
| Middleware | TimeoutMiddleware | TimeoutMiddleware |
| Test | {ClassName}Test | SignalTimeoutExecutorTest |
final readonly class TimeoutConfig
{
public function __construct(
public float $durationSeconds,
public ?callable $fallback = null,
public bool $shouldRetry = false,
public string $operationName = 'unknown',
) {}
public static function fast(): self; // 3 seconds
public static function standard(): self; // 10 seconds
public static function slow(): self; // 30 seconds
public static function of(float $seconds): self;
}
interface TimeoutInterface
{
/**
* @template T
* @param callable(): T $operation
* @return T
* @throws TimeoutException
*/
public function execute(callable $operation, TimeoutConfig $config): mixed;
}
final class TimeoutException extends \RuntimeException
{
public function __construct(
public readonly float $elapsedSeconds,
public readonly float $timeoutSeconds,
public readonly string $operationName,
?\Throwable $previous = null,
) {
parent::__construct(
sprintf('Operation "%s" timed out after %.2fs (limit: %.2fs)', $operationName, $elapsedSeconds, $timeoutSeconds),
0,
$previous,
);
}
}
$timeout = $timeoutFactory->create();
try {
$result = $timeout->execute(
operation: fn() => $httpClient->request('GET', $url),
config: TimeoutConfig::of(5.0),
);
} catch (TimeoutException $e) {
$logger->warning('API call timed out', [
'operation' => $e->operationName,
'elapsed' => $e->elapsedSeconds,
'timeout' => $e->timeoutSeconds,
]);
return $cachedResult;
}
$result = $circuitBreaker->execute(
operation: fn() => $timeout->execute(
operation: fn() => $api->call($request),
config: TimeoutConfig::of(5.0),
),
fallback: fn() => $cache->get($cacheKey),
);
| Anti-pattern | Problem | Solution |
|---|---|---|
| No timeout | Indefinite blocking | Always set explicit timeout |
| Too aggressive | Fail on normal slow responses | Tune per-operation |
| Global timeout | One size doesn't fit all | Per-operation config |
| No fallback | Hard failure on timeout | Provide degraded response |
| Ignoring context | Can't debug timeouts | Include operation name |
| Nested timeouts | Outer timeout kills inner | Coordinate timeout budgets |
For complete PHP templates and examples, see:
references/templates.md — All component templatesreferences/examples.md — API call, DB query examples and testsnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accGenerates PHP 8.4 Circuit Breaker pattern for resilience, with state management, fallbacks, metrics, factory, registry, and unit tests. Prevents cascading failures in services.
Prevents resource exhaustion and hung requests by enforcing timeouts, using AbortController, and propagating deadlines across service boundaries.
Assists implementing circuit breakers, retries, bulkheads, and resilience patterns for fault-tolerant distributed systems.