Search by

phil / virtual-queue

phil

Let visitors queue for a booth or an activity from their phone: calls by turn or boarding group, a return window, and waits estimated on the real pace.

0.1.0-alpha 2026-11-29 22:00 UTC

This package is auto-updated.

Last update: 2026-11-30 02:53:01 UTC


README

Let visitors queue for a booth or an activity from their phone: calls by turn or boarding group, a return window, and waits estimated on the real pace.

phil/virtual-queue is a plain PHP library. A visitor scans a code at a booth, a ride or a demo table, gets a ticket and walks away; the staff call the next parties when there is room, each called visitor has a return window to come back, and everyone sees their place and an estimated wait that follows the pace actually measured. The library holds the rules and the state of one line; the application stores it, shows it and sends the messages.

  • Tickets without an account: a short code of ten characters, 50 random bits, that a visitor reads on a screen, types on a phone or scans from a QR code; typing mistakes such as O for 0 are forgiven.
  • Calls by seats: the staff call as many parties as there are seats free, in order; a party too large waits for the next call, or lets smaller parties behind it fill the gap when the staff ask for it. One ticket may also be called out of turn.
  • Boarding groups: when demand exceeds what a day can serve, tickets fall into groups of a fixed size and the staff open the groups one after the other.
  • A return window: a called visitor has a set time to come; past it, the ticket is missed, and the staff may put it back in the line with its number, as many times as the policy allows.
  • Estimated waits: the parties ahead times the pace measured on the parties served during the last half hour, or the configured service time while too few were served.
  • Reminders: the line lists the visitors whose turn is near — a few parties ahead, or a few minutes away — once each, for the application to notify.
  • Safe to store: a line encodes to versioned JSON, decoded within a size and a depth limit, every member checked; its version lets the application save it only over the state it loaded.
  • Worker-safe: nothing is kept outside the line, so one long-running worker serves any number of lines.

Status

Part State
Policies, tickets and their states Implemented and tested
Joining, calling by seats, serving, leaving Implemented and tested
Boarding groups Implemented and tested
Return window, missed tickets and requeues Implemented and tested
Wait estimates and reminders Implemented and tested
Ticket codes Implemented and tested
The JSON codec of a line Implemented and tested, fuzzed

Documentation

Document What it covers
Installation Requirements, installing, a first line.
Calls Joining, calls by seats, groups, the return window, serving and leaving.
Estimates and reminders How waits are estimated and when visitors are reminded.
Storage The JSON codec, versions, locks and ticket codes.
Extension points What an application may replace or add, and what is stable.
Testing The tests, the fuzz target and the benchmark.
Reference Every public type, with its role.

Quick start

composer require phil/virtual-queue
use Phil\VirtualQueue\Line;
use Phil\VirtualQueue\QueuePolicy;
use Phil\VirtualQueue\TicketCode;

$line = new Line(new QueuePolicy(capacity: 400, maxPartySize: 6, returnWindow: 600));

// A visitor scans the booth's code.
$ticket = $line->join(TicketCode::generate(), partySize: 3, now: $clock->now());
$line->estimate($ticket->id, $clock->now())->minutes();   // 0: nobody is ahead

// The staff have eight seats free.
foreach ($line->callNext(8, $clock->now()) as $called) {
    $bus->dispatch(new TicketCalled($called->id));
}

$line->serve($ticket->id, $clock->now());

Requirements

PHP 8.5 or later, and nothing else.

Contributing

Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.

License

MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See LICENSE.