Download the PHP package rasuvaeff/yii3-ab-testing-db without Composer
On this page you can find all versions of the php package rasuvaeff/yii3-ab-testing-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rasuvaeff/yii3-ab-testing-db
More information about rasuvaeff/yii3-ab-testing-db
Files in rasuvaeff/yii3-ab-testing-db
Package yii3-ab-testing-db
Short Description Database-backed experiment provider for Yii3 A/B testing
License BSD-3-Clause
Homepage https://github.com/rasuvaeff/yii3-ab-testing-db
Informations about the package yii3-ab-testing-db
rasuvaeff/yii3-ab-testing-db
Database-backed experiment provider for Yii3 A/B testing. Implements the
ExperimentProvider interface from rasuvaeff/yii3-ab-testing and reads
experiment configuration from a database table in a single query, so experiments
can be toggled and reweighted at runtime without a deploy.
Using an AI coding assistant? llms.txt contains a compact API reference you can ingest in your prompt context.
Requirements
- PHP 8.3+
rasuvaeff/yii3-ab-testing^1.0yiisoft/db^2.0yiisoft/db-migration^2.0 (ships the table migration)- a PSR-16 cache implementation — required transitively by
yiisoft/db2.0 (e.g.yiisoft/cache)
Installation
With Yii3 config-plugin this package binds ExperimentProvider automatically — do
not also bind ExperimentProvider in your application or another backend, or
yiisoft/config reports a Duplicate key error.
Database schema
Create the ab_experiments table (adjust types for your RDBMS):
| Column | Type | Default | Description |
|---|---|---|---|
name |
VARCHAR(190) PK |
— | Experiment name (core regex: /^[a-z][a-z0-9_-]*$/) |
enabled |
BOOLEAN |
true |
Disabled experiment returns the fallback variant |
salt |
VARCHAR(190) |
'' |
Empty string falls back to the experiment name |
fallback_variant |
VARCHAR(190) |
'' |
Must be one of the variants keys |
variants |
JSON/TEXT |
'{}' |
JSON object {"variant": weight}, non-negative integer weights |
A row's variants looks like {"control":50,"green":50}. The total weight must
be greater than zero and fallback_variant must match one of the keys, or the row
is rejected with InvalidExperimentRowException.
Migration
The package ships a migration (migrations/) for yiisoft/db-migration.
Register the source path in your app's config/params.php:
Then apply and revert it with Yii Console:
The table name defaults to ab_experiments and must match the table argument of
DbExperimentProvider. To use a custom name, bind the migration constructor argument:
Usage
Basic DB provider
With PSR-16 caching
getExperiments() runs on every registry build (per request). Without caching that
is a DB query per request — wrap the provider in CachedExperimentProvider:
Clear cache
API reference
| Class | Description |
|---|---|
DbExperimentProvider |
Reads all experiments from DB in one SELECT * |
CachedExperimentProvider |
PSR-16 decorator, caches the entire experiment set with TTL |
InvalidExperimentRowException |
Thrown when a DB row has invalid structure or yields an invalid experiment |
Security
- Assignment hashing, fallback handling, forced/disabled logic remain in the core package — the DB adapter is only a configuration source.
- Invalid row data (missing columns, malformed
variantsJSON, wrong types, negative weights, invalid experiment name, unknown fallback, zero total weight) throwsInvalidExperimentRowExceptioninstead of silently mis-assigning. Core validation errors are wrapped, so callers only need to catch one exception type. - No SQL injection risk: the table name is quoted via the yiisoft/db quoter.
- Reweighting shifts buckets. Safe to flip
enabled(kill switch). Changing weights or the variant set shifts bucket boundaries and reshuffles subjects — useyii3-ab-testing-websticky assignment to pin subjects across such changes.
Examples
See examples/ for runnable scripts.
Development
License
BSD-3-Clause. See LICENSE.md.
All versions of yii3-ab-testing-db with dependencies
ext-json Version *
psr/simple-cache Version ^3.0
rasuvaeff/yii3-ab-testing Version ^1.4
yiisoft/db Version ^2.0
yiisoft/db-migration Version ^2.0