Skip to content

Documentation

PHP SDK: State and Resuming Traversal

These methods are available through $ctx->state(). Store only what is needed to resume, such as a cursor, page number, or counters. This does not replace emit and is not a shared database for arbitrary scenarios.

SDK reference

Methods

get

get(string $key, mixed $default = null): mixed

Read a saved state value.

$page = (int) $ctx->state()->get('next_page', 1);

Result and notes. Returns the value or default. Use short, clear keys and check the value's type.

set

set(string $key, mixed $value): void

Save a state value to resume traversal later.

$ctx->flush();
$ctx->state()->set('next_page', 3);

Result and notes. Returns nothing. Marking progress is not a transaction with a product save. Repeating part of a traversal should be safe because emit keys are stable.

incr

incr(string $key, int $by = 1): int

Increase an integer state counter.

$processed = $ctx->state()->incr('processed', 1);

Result and notes. Returns the new integer. by defaults to 1.