pablojoan/feature
Composer 安装命令:
composer require pablojoan/feature
包简介
Feature flagging API used for operational rampups and A/B testing
关键字:
README 文档
README
Requires PHP 8.3 and above.
Installation
composer require pablojoan/feature
Basic Usage
use PabloJoan\Feature\Features; // Import the namespace. $featureConfigs = [ 'foo' => [ 'variants' => [ 'variant1' => 100, //100% chance this variable will be chosen 'variant2' => 0 //0% chance this variable will be chosen ] ], 'bar' => [ 'variants' => [ 'variant1' => 25, //25% chance this variable will be chosen 'variant2' => 25, //25% chance this variable will be chosen 'variant3' => 50 //50% chance this variable will be chosen ], 'bucketing' => 'id' //same id string will always return the same variant ] ]; $features = new Features($featureConfigs); $features->isEnabled(featureName: 'foo'); // true $features->getEnabledVariant(featureName: 'foo'); // 'variant1'
For a quick summary and common use cases, please read the rest of this README.
Feature API
Feature flagging API used for operational rampups and A/B testing.
The Feature API is how we selectively enable and disable features at a very fine grain as well as enabling features for a percentage of users for operational ramp-ups and for A/B tests. A feature can be completely enabled, completely disabled, or something in between and can comprise a number of related variants.
The two main API entry points are:
$features->isEnabled(featureName: 'my_feature')
which returns true when my_feature is enabled and, for multi-variant features:
$features->getEnabledVariant(featureName: 'my_feature')
which returns the name of the particular variant which should be used.
The single argument to each of these methods is the name of the feature to test.
A typical use of $features->isEnabled for a single-variant feature
would look something like this:
if ($features->isEnabled(featureName: 'my_feature')) { // do stuff }
For a multi-variant feature, we can determine the appropriate code to run for each variant with something like this:
switch ($features->getEnabledVariant(featureName: 'my_feature')) { case 'foo': // do stuff appropriate for the 'foo' variant break; case 'bar': // do stuff appropriate for the 'bar' variant break; }
If a feature is bucketed by id, then we pass the id string to
$features->isEnabled and $features->getEnabledVariant as a second parameter
$isMyFeatureEnabled = $features->isEnabled( featureName: 'my_feature', id: 'unique_id_string' ); $variant = $features->getEnabledVariant( featureName: 'my_feature', id: 'unique_id_string' );
Configuration cookbook
There are a number of common configurations so before I explain the complete syntax of the feature configuration stanzas, here are some of the more common cases along with the most concise way to write the configuration.
A totally enabled feature:
$server_config['foo'] = ['variants' => ['enabled' => 100]];
A totally disabled feature:
$server_config['foo'] = ['variants' => ['enabled' => 0]];
Feature with winning variant turned on for everyone
$server_config['foo'] = ['variants' => ['blue_background' => 100]];
Single-variant feature ramped up to 1% of users.
$server_config['foo'] = ['variants' => ['enabled' => 1]];
Multi-variant feature ramped up to 1% of users for each variant.
$server_config['foo'] = [ 'variants' => [ 'blue_background' => 1, 'orange_background' => 1, 'pink_background' => 1, ], ];
Enabled for 10% of regular users.
$server_config['foo'] = [ 'variants' => ['enabled' => 10] ];
Feature ramped up to 1% of requests, bucketing at random rather than by id
$server_config['foo'] = [ 'variants' => ['enabled' => 1], 'bucketing' => 'random' ];
Feature ramped up to 40% of requests, bucketing by id rather than at random
$server_config['foo'] = [ 'variants' => ['enabled' => 40], 'bucketing' => 'id' ];
Single-variant feature in 50/50 A/B test
$server_config['foo'] = ['variants' => ['enabled' => 50]];
Multi-variant feature in A/B test with 20% of users seeing each variant (and 40% left in control group).
$server_config['foo'] = [ 'variants' => [ 'blue_background' => 20, 'orange_background' => 20, 'pink_background' => 20 ], ];
Configuration details
Each feature’s config stanza controls when the feature is enabled and what variant should be used when it is.
The value of a feature config stanza is an array with a number of special
keys, the most important of which is 'variants'.
The value of the 'variants' property an array whose keys are names of variants
and whose values are the percentage of requests that should see each variant.
The remaining feature config property is 'bucketing'. Bucketing specifies
how users are bucketed when a feature is enabled for only a percentage of users.
The default value, 'random', causes each request to be bucketed independently,
meaning that the same user will be in different buckets on different requests.
This is typically used for features that should have no user-visible effects
but where we want to ramp up something like the switch from master to shards
or a new version of JS code.
The bucketing value 'id', causes bucketing to be based on the given id.
Errors
There are a few ways to misuse the Feature API or misconfigure a feature that may be detected. (Some of these are not currently detected but may be in the future.)
-
Setting the percentage value of a variant in
'variants'to a value less than 0 or greater than 100. -
Setting
'variants'such that the sum of the variant percentages is greater than 100. -
Setting
'variants'to a non-array value. -
Setting
'bucketing'to any value that is not'id'or'random'.
pablojoan/feature 适用场景与选型建议
pablojoan/feature 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 32 次下载、GitHub Stars 达 27, 最近一次更新时间为 2017 年 12 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「feature」 「toggle」 「ab-test」 「feature-flags」 「feature-toggles」 「feature-toggle」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pablojoan/feature 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pablojoan/feature 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pablojoan/feature 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A block that displays featured content - large image, title, description and link.
Laravel Eloquent boolean & timestamp flagged attributes behavior.
MaxAl Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
yii2 toggle column for update in gridview
Rinvex Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
Rinvex Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 28
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unlicense
- 更新时间: 2017-12-28