The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideRecipesAPI Reference
Dev guideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Configure the PHP SDK event dispatcher

How to configure the event dispatcher for HTTP requests made from every impression or conversion in the Optimizely Feature Experimentation PHP SDK.

The Optimizely Feature Experimentation SDKs make HTTP requests for every decision event or conversion event that gets triggered. Each SDK has a built-in event dispatcher for handling these events, but we recommend overriding it based on the specifics of your environment.

The PHP SDK has an out-of-the-box synchronous dispatcher. Optimizely recommends customizing the event dispatcher you use in production to ensure that you queue and send events in a manner that scales to the volumes handled by your application. Customizing the event dispatcher allows you to take advantage of features like batching, which makes it easier to handle large event volumes efficiently or to implement retry logic when a request fails. You can build your dispatcher from scratch or start with the provided dispatcher.

🚧

Important

Performance risks with synchronous dispatchers

It is important to customize your event dispatcher when using an SDK for with a synchronous built-in event dispatcher to ensure that you can retrieve variations without waiting for the corresponding network request to return.

The examples show that to customize the event dispatcher, initialize the Optimizely client (or manager) with an event dispatcher instance.

use Optimizely\Event\Dispatcher\DefaultEventDispatcher;

/** 
 * Create an Optimizely client with the default event dispatcher.
 * Please note, if not provided it will default to this event dispatcher.
 */
$optimizelyClient = new Optimizely($datafile, new DefaultEventDispatcher());

/**
 * You can provide your own implementation of the event dispatcher
 * for sending events to Optimizely. It should however implement
 * Optimizely\Event\Dispatcher\EventDispatcherInterface.
 */

❗️

Warning

The maximum payload size is 3.5 MB. Optimizely rejects requests with a 400 response code, Bad Request Error, if the batch payload exceeds this limit.

The size limitation is because of the Optimizely Events API, which Feature Experimentation uses to send data to Optimizely.

The most common cause of a large payload size is a high batch size. If your payloads exceed the size limit, try configuring a smaller batch size.

The event dispatcher should implement a dispatchEvent function, which takes in three arguments: httpVerb, url, and params, all of which are created by the internal EventBuilder class. In this function, you should send a POST request to the given url using the params as the body of the request (be sure to stringify it to JSON) and {content-type: 'application/json'} in the headers.

🚧

Important

If you are using a custom event dispatcher, do not modify the event payload returned from Optimizely Feature Experimentation. Modifying this payload will alter your results.

The Feature Experimentation PHP SDK includes a basic synchronous event dispatcher.