phasync
Coordination across workers / SubscriberLagException

Exception

SubscriberLagException

A subscription fell further behind its topic than its $maxLag seconds, see Subscription.

Introduction#

Thrown from the subscription's loop, which ends. A client that can't keep up is better disconnected: it reconnects and catches up from storage. An OrderedChannel subscription also throws it when messages were lost because its worker did not run for about 30 s.

Class synopsis#

class SubscriberLagException extends RuntimeException implements \Stringable, \Throwable {

}

Examples#

Example 1A subscriber that fell behind
use Swerve\SubscriberLagException;
use Swerve\Swerve;

phasync::run(function () {
    $subscription = Swerve::subscribe('prices', maxLag: 0.1);
    Swerve::publish('prices', 101.5);

    phasync::sleep(0.3);                      // busy elsewhere for longer than maxLag

    try {
        foreach ($subscription as $price) {
            echo "price $price\n";
        }
    } catch (SubscriberLagException) {
        echo "fell behind: disconnect, and let the client catch up from storage\n";
    }
});
Output
fell behind: disconnect, and let the client catch up from storage
Example 2
try {
    foreach (Swerve::subscribe('chat', maxLag: 5.0) as $message) {
        $ws->send(json_encode($message));
    }
} catch (SubscriberLagException) {
    $ws->end(1013, 'too slow');
}

See also#