Initialization
To create a VWO Client instance, you need to initialize the VWO FE Php SDK. This client instance serves as the core interface for conducting Feature Experimentation(A/B and personalization) within your application.
Usage
$vwoClient = VWO::init([
'accountId' => your_account_id,
'sdkKey' => your_sdk_key,
]);The init() function is called with the sdkKeyand accountId. It initializes and returns a VWO Client ObjectvwoClient, which can be used to perform feature
This client object allows you to run experiments, track events, and enable/disable feature flags.
Parameter Definitions
Paramter | Type | Description |
|---|---|---|
accountId Required | Integer | Your VWO application's Account ID. |
sdkKey Required | String | A unique environment key is provided to you inside the Websites & Apps section in the VWO application, under Default Project. |
logger Optional | Object | An optional logger object that defines the logging behavior. For more details, please check - Logger |
storage Optional | Object | Storage Service, if required, can be implemented using this parameter. For more details, please check - Storage Service |
retryConfig | Object | Customize retry behavior by passing a retryConfig in the init options. For more details, please check - Retry Configuration |
gatewayService Optional | Object | If using the FE Gateway Service, this object will specify the location and port where the gateway service is deployed on your servers. |
integrations Optional | Object | A callback function that receives data, which can be pushed to any external tool that you need to integrate with. For more details, please check - Integrations |
settingsConfig Optional | Object | Use these to configure the network call timeout for fetching settings from VWO. Refer this. |
settings Optional | Object | Pass the already fetched settings so the SDK can initialize instantly, without waiting to fetch settings from VWO. Refer this. |
Logger
VWO by default logs all ERROR level messages to your server console. To gain more control over VWO's logging behavior, you can use the logger parameter in the init configuration.
// Init options with logger
$vwoClient1 = VWO::init([
'sdkKey' => '32-alpha-numeric-sdk-key',
'accountId' => '123456',
'logger' => [
'level' => 'DEBUG',
],
]);Please click here for more advanced logger options.
Storage
By default, the SDK operates in stateless mode, evaluating flags on each getFlag call. To improve performance and consistency, you can use a custom storage mechanism to cache decisions, ensuring stable user experiences and reducing application load.
// Init options with storage
$vwoClient = VWO::init([
'sdkKey' => '32-alpha-numeric-sdk-key',
'accountId' => '123456',
'storage' => $storageConnector,
]);Please click here to learn more about storage implementation.
Gateway Service
The VWO FE Gateway Service enhances Feature Experimentation (FE) SDKs by enabling pre-segmentation based on user location and user agent. It ensures minimal latency and improved security. The service can be customized via the gatewayService parameter during initialization.
// Init options with gatewayService
$vwoClient = VWO::init([
'sdkKey' => '32-alpha-numeric-sdk-key',
'accountId' => '123456',
'gatewayService' => [
'url' => 'https://custom.gateway.com',
],
]);Please click here to learn more about gateway service.
Integrations
VWO FE SDKs provide seamless integration with third-party tools like analytics platforms, monitoring services, customer data platforms (CDPs), and messaging systems. This is achieved through a simple yet powerful callback mechanism that receives VWO-specific properties and can forward them to any third-party tool of your choice.
// Init options with integrations
$vwoClient = VWO::init([
'sdkKey' => '32-alpha-numeric-sdk-key',
'accountId' => '123456',
'integrations' => [
'callback' => function ($properties) {
echo "Integrations callback: " . json_encode($properties) . PHP_EOL;
}
]
]);Please click here to learn more about Integrations,.
Settings Configuration
Use these options to define and control the timeout duration for the network request made to fetch settings from VWO, ensuring the SDK does not wait indefinitely and behaves predictably under slow or unreliable network conditions.
$vwoClient = VWO::init([
'accountId' => '123456',
'sdkKey' => '32-alpha-numeric-sdk-key',
'settingsConfig' => [
// Network timeout for settings fetch in milliseconds (default: 50000)
'timeout' => 2000
],
]);Initialization with Explicit Settings
The SDK provides the ability to reduce initialization time by allowing users to explicitly pass in settings instead of fetching them automatically. This can be especially useful in environments where you need to optimize for faster setup or if you already have the necessary settings retrieved from a remote server.
Please refer to this document for more information on retrieving settings.
$settingsStringified = '{
"accountId": 123456,
"sdkKey": "32-alpha-numeric-sdk-key",
"features": {
},
"campaigns": {
},
"version": 1,
}';
$settings = json_decode($settingsStringified, true);
$vwoClient = VWO::init([
'sdkKey' => '32-alpha-numeric-sdk-key',
'accountId' => '123456',
'settings' => $settings
]);Retry Configuration
The SDK includes a built-in retry mechanism to improve reliability when network requests fail due to transient issues such as timeouts or temporary connectivity problems. You can fully control this behavior by providing a retryConfig object during SDK initialization.
$vwoClient = VWO::init([
'sdkKey' => '32-alpha-numeric-sdk-key',
'accountId' => '123456',
'shouldWaitForTrackingCalls' => true,
'retryConfig' => [
'shouldRetry' => true, // default: true
'maxRetries' => 3, // default: 3
'initialDelay' => 2, // seconds; default: 2
'backoffMultiplier' => 2, // delays: 2s, 4s, 8s; default: 2
],
]);Retry works for synchronous (cURL) calls only, and you should pass 'shouldWaitForTrackingCalls' => true, in the init configration to enable synchronous (cURL) calls and retry.
Please click here to learn more about Retry Mechanism
Updated 11 days ago
