Pool::recover

(PHP 8.6+, True Async 1.0)

public Pool::recover(): void

Transitions the pool to the RECOVERING state. In this state, the pool allows a limited number of requests through to check service availability. If requests succeed, the Circuit Breaker automatically transitions the pool to the ACTIVE state. If requests continue to fail, the pool returns to INACTIVE.

Parameters

This method takes no parameters.

Return Value

No value is returned.

Examples

Example #1 Recovery attempt

<?php

use Async\Pool;
use Async\CircuitBreakerState;

$pool = new Pool(
    factory: fn() => new HttpClient('https://api.example.com'),
    max: 10
);

// Pool is deactivated, try to recover
if ($pool->getState() === CircuitBreakerState::INACTIVE) {
    $pool->recover();
    echo "Pool transitioned to recovery mode\n";
    // Circuit Breaker will allow probe requests through
}

Example #2 Periodic recovery attempts

<?php

use Async\Pool;
use Async\CircuitBreakerState;

spawn(function() use ($pool) {
    while (!$pool->isClosed()) {
        if ($pool->getState() === CircuitBreakerState::INACTIVE) {
            $pool->recover();
        }

        suspend(delay: 10000); // check every 10 seconds
    }
});

See Also