Search by

phil / spaced-repetition

phil

Schedule reviews so learners remember more while studying less: the FSRS-6 algorithm, learning steps, a review queue and review logs to replay.

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

This package is auto-updated.

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


README

Schedule reviews so learners remember more while studying less: the FSRS-6 algorithm, learning steps, a review queue and review logs to replay.

phil/spaced-repetition is a plain PHP library without dependencies. It decides when a learner should see a card again: right before they would forget it. A course, a vocabulary deck, a set of rules to learn or the questions of a quiz become cards; the learner answers Again, Hard, Good or Easy; the scheduler gives the card its next date and the log of the review.

  • FSRS-6: the Free Spaced Repetition Scheduler, from its published formulas. Each card has a stability — the days after which recall falls to 90 % — and a difficulty from 1 to 10; each answer moves both. The published default weights serve a learner nobody has optimised for yet; weights trained on a learner's own logs replace them, and nineteen-weight FSRS-5 vectors are read too.
  • A retention to aim for: the learner, or the course, picks the probability of recall at which a card falls due, from 70 % to 99 %; a lower retention means longer intervals and fewer reviews.
  • Learning and relearning steps: a new or forgotten card comes back after short waits — one and ten minutes by default — before it gets an interval in days.
  • Buttons that show their wait: preview() gives what each of the four answers would do, for « 10 min », « 2 days », « 8 days » on a review screen.
  • A queue for a session: cards in learning first, then due cards the most likely forgotten first, then new cards, each within its limit. Missed days carry no penalty and there is no streak to lose.
  • Logs that replay: every review gives a log of identifiers and figures, never what the card asks. Replaying a card's logs under new weights gives the card those weights would have given.
  • Stable on every server: intervals of three days or more are spread so that cards learned together do not fall due together, from a hash of the card and its review number; the same review always gives the same date, and the scheduler keeps no state, safe in a long-running worker.
  • Versioned JSON: cards and logs encode to small JSON objects with their version and algorithm, and decoding checks every field, within a size limit.

Status

Part State
The FSRS-6 formulas, with FSRS-5 weights read Implemented and tested
Learning and relearning steps, spread intervals, same-day reviews Implemented and tested
Preview, probability of recall, forgetting a card Implemented and tested
Replaying logs under other parameters Implemented and tested
The review queue Implemented and tested
The JSON codec of cards and logs Implemented and tested, fuzzed

Documentation

Document What it covers
Installation Requirements, installing, a first review.
The algorithm FSRS-6: stability, difficulty, recall, each formula and its weights.
Scheduling States, steps, intervals, the spread, the preview, the queue and replays.
Storage Columns for a card, the JSON codec, logs and optimised weights.
Extension points The parameters, the source of the spread, what is stable.
Testing The tests, the fuzz target and the benchmark.
Reference Every public type, with its role.

Quick start

composer require phil/spaced-repetition
use Phil\SpacedRepetition\Card;
use Phil\SpacedRepetition\Rating;
use Phil\SpacedRepetition\Scheduler;

$scheduler = new Scheduler();
$now = new DateTimeImmutable();

$card = Card::new('deck-3/card-42', $now);
$outcome = $scheduler->review($card, Rating::Good, $now);

$outcome->card->due;          // ten minutes from now: the second learning step
$outcome->card->state;        // CardState::Learning
$outcome->log;                // the review, to keep for replays and optimisers

foreach ($scheduler->preview($outcome->card, $outcome->card->due) as $rating => $next) {
    echo $rating, ': ', $next->waitSeconds(), ' s', PHP_EOL;   // the wait each button would give
}

Requirements

PHP 8.5 or later.

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.