PHP code example of rasuvaeff / yii3-ab-testing-db
1. Go to this page and download the library: Download rasuvaeff/yii3-ab-testing-db library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Rasuvaeff\Yii3AbTesting\AbTesting;
use Rasuvaeff\Yii3AbTesting\WeightedHashAssignmentStrategy;
use Rasuvaeff\Yii3AbTestingDb\DbExperimentProvider;
$provider = new DbExperimentProvider(
db: $connection, // yiisoft/db ConnectionInterface
table: 'ab_experiments', // optional, default is 'ab_experiments'
);
$ab = new AbTesting(provider: $provider, strategy: new WeightedHashAssignmentStrategy());
if ($ab->is(experiment: 'checkout-button', variant: 'green', subjectId: (string) $userId)) {
// green variant
}
use Rasuvaeff\Yii3AbTestingDb\CachedExperimentProvider;
$cached = new CachedExperimentProvider(
inner: $provider,
cache: $psr16Cache, // PSR-16 CacheInterface
ttl: 60, // seconds
);
$ab = new AbTesting(provider: $cached, strategy: new WeightedHashAssignmentStrategy());
$cached->clear(); // removes cached experiments, next call reloads from DB
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.