Download the PHP package growthbook/growthbook without Composer

On this page you can find all versions of the php package growthbook/growthbook. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package growthbook

GrowthBook - PHP

Powerful Feature flagging and A/B testing for PHP.

Build Status

Installation

GrowthBook is available on Composer:

composer require growthbook/growthbook

Quick Usage

Some of the feature flags you evaluate might be running an A/B test behind the scenes which you'll want to track in your analytics system.

At the end of the request, you can loop through all experiments and track them however you want to:

Loading Features

There are 2 ways to load features into the SDK. You can use loadFeatures with a Client Key and API Host. Or, you can manually fetch and cache feature flags and pass them in with the withFeatures method.

loadFeatures method

The loadFeatures method can fetch features from the GrowthBook API for you.

By default, there is no caching enabled. You can enable it by passing any PSR16-compatible instance into the withCache method.

Caching is required for production usage

To load features, we require a PSR-17 (HttpClient) and PSR-18 (RequestFactoryInterface) compatible library like Guzzle to be installed.

We will auto-discover most HTTP libraries without any configuration required, but if you prefer to specify it explicitly, you can use the withHttpClient method. Note - you'll need to specify both an HttpClient and a RequestFactoryInterface implementation.

The loadFeatures method takes 3 arguments:

withFeatures method

If you prefer to have full control over the fetching/caching behavior, you can use the withFeatures method instead to pass an associative array of features into the SDK.

The Growthbook Class

The Growthbook class has a number of properties. These can be set using a Fluent interface or can be passed into a constructor using an associative array. Every property also has a getter method if needed. Here's an example:

Note: you can also use the fluent methods (e.g. withFeatures) at any point to update properties.

Attributes

You can specify attributes about the current user and request. These are used for two things:

  1. Feature targeting (e.g. paid users get one value, free users get another)
  2. Assigning persistent variations in A/B tests (e.g. user id "123" always gets variation B)

Attributes can be any JSON data type - boolean, integer, float, string, or array.

If you want to update attributes later, please note that the withAttributes method completely overwrites the attributes object. You can use array_merge if you only want to update a subset of fields:

Tracking Experiments

Any time an experiment is run to determine the value of a feature, you want to track that event in your analytics system.

You can either do this via a callback function:

Or track all events at the end of the request by looping through an array:

Or, you can pass the impressions onto your front-end and fire analytics events from there. To do this, simply add a block to your template (shown here in plain PHP, but similar idea for Twig, Blade, etc.).

Below are examples for a few popular front-end tracking libraries:

Google Analytics

Segment

Mixpanel

Logging

GrowthBook can output log messages to help you debug your feature flags and experiments.

We support any PSR-3 comaptible logger. We implement a fluent interface (withLogger) as well as the standard LoggerAware interface (setLogger).

Using Features

There are 3 main methods for interacting with features.

In addition, you can use $growthbook->getFeature("feature-key") to get back a FeatureResult object with the following properties:

Inline Experiments

Instead of declaring all features up-front and referencing them by ids in your code, you can also just run an experiment directly. This is done with the $growthbook->runInlineExperiment method:

As you can see, there are 2 required parameters for experiments, a string key, and an array of variations. Variations can be any data type, not just strings.

There are a number of additional settings to control the experiment behavior. The methods are all chainable. Here's an example that shows all of the possible settings:

Inline Experiment Return Value

A call to runInlineExperiment returns an ExperimentResult object with a few useful properties:

The inExperiment flag will be false if the user was excluded from being part of the experiment for any reason (e.g. failed targeting conditions).

The hashUsed flag will only be true if the user was randomly assigned a variation. If the user was forced into a specific variation instead, this flag will be false.


All versions of growthbook with dependencies

PHP Build Version
Package Version
Requires psr/log Version ^1.0|^2.0|^3.0
psr/simple-cache Version ^1.0|^2.0|^3.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.0|^2.0
php-http/discovery Version ^1.15
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package growthbook/growthbook contains the following files

Loading the files please wait ....