Skip to content

Make cache warmup timeout configurable #142

@s2x

Description

@s2x

Context

PR #141 introduced a CACHE_WARMUP_TIMEOUT constant (30 seconds) in Runner.php for the forked cache warmup process timeout. Currently this value is hardcoded and cannot be changed without modifying the source.

Architecture Note

Runner is NOT a container service — it is created by Runtime::getRunner() before the DI container is available. Bundle config cannot reach Runner at runtime. The only reliable path is $_SERVER env var (same pattern as existing APP_CACHE_DIR).

Bundle config cache_warmup_timeout is added for documentation and to set the container parameter (usable by other services), but Runner reads exclusively from $_SERVER[WORKERMAN_CACHE_WARMUP_TIMEOUT] with a default fallback.

Implementation Plan

Task 1: Add cache_warmup_timeout to bundle configuration

Files: src/config/configuration.php, src/config/services.php

  1. Add config node in src/config/configuration.php after stop_timeout:
->integerNode('cache_warmup_timeout')
    ->info('Max seconds to wait for cache warmup in forked process. Can be overridden with WORKERMAN_CACHE_WARMUP_TIMEOUT env var.')
    ->defaultValue(30)
    ->end()
  1. Add container parameter in src/config/services.php:
$container->setParameter('workerman.cache_warmup_timeout', $config['cache_warmup_timeout']);

Task 2: Update Runner to use configurable timeout

Files: src/Runner.php

  1. Remove CACHE_WARMUP_TIMEOUT constant
  2. Add getCacheWarmupTimeout() method (mirrors getCacheDir() pattern):
private function getCacheWarmupTimeout(): int
{
    if (isset($_SERVER['WORKERMAN_CACHE_WARMUP_TIMEOUT'])) {
        return (int) $_SERVER['WORKERMAN_CACHE_WARMUP_TIMEOUT'];
    }

    return 30;
}
  1. Replace $timeout = self::CACHE_WARMUP_TIMEOUT; with $timeout = $this->getCacheWarmupTimeout();

Task 3: Update tests

Files: tests/RunnerTest.php

  1. Replace CACHE_WARMUP_TIMEOUT assertion with WORKERMAN_CACHE_WARMUP_TIMEOUT and getCacheWarmupTimeout
  2. Add testCacheWarmupTimeoutDefaultsTo30 structural test

Task 4: Verify

  • Run vendor/bin/phpunit
  • Run vendor/bin/phpstan analyse
  • Run vendor/bin/php-cs-fixer fix --dry-run

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions