Cancel work in flight
Stopping requests and long iterations with Cancellation in the SUQO PHP SDK.
PHP has no ambient cancellation, so the SDK brings its own: Suqo\Cancellation, a one-way latch that is the last parameter of every request method.
| Method | Notes |
|---|---|
Cancellation::none() | A fresh, never-cancelled token. What every method uses when you pass null. |
cancel() | Trips the latch. Idempotent, and cannot be untripped. |
isCancelled() |
use Suqo\Cancellation;
$token = new Cancellation();
pcntl_signal(SIGTERM, static fn () => $token->cancel());
foreach ($suqo->subscriptions->autoPaging(cancellation: $token) as $subscription) {
handle($subscription);
}A tripped token raises CancelledError, which is never retried and stays distinct from the NetworkError a timeout produces — so "I stopped it" and "the network stopped it" remain separable in your logs.
Where it is honoured
Four points, which is what makes it useful on a long job rather than only between calls:
- before an attempt starts;
- mid-flight, through cURL's progress callback;
- during retry backoff, so a token tripped mid-wait raises immediately rather than completing the sleep;
- at each page boundary while auto-paging.
The class is not final, so you can subclass it — a token that trips on a deadline, for instance.
With an injected client
Mid-flight cancellation is a property of the HTTP client. The default cURL client honours it; the PSR-18 adapter checks the token before the request and after it returns, never mid-flight, because PSR-18 cannot express it. See Inject an HTTP client.