Php Core SDK Migration Guide
Migrate from the legacy Php Server SDK to the new Php Core SDK
Why migrate?
- Performance: PHP Core evaluates faster than the legacy SDK.
- New Features: Access to Parameter Stores, CMAB (Contextual Multi-Armed Bandits), observabilityClient, and more.
- Future Support: All new features and improvements are only available in PHP Core.
- Maintenance: The legacy PHP SDK is in maintenance mode and only receives critical bug fixes.
Installation and setup
For the PHP Core SDK, configure composer.json to run the provided post-install.php file:
composer require statsig/statsig-php-core
// composer.json
{
"name": "awesome-php-project",
...
"scripts": {
...
"post-install-cmd": [
"cd vendor/statsig/statsig-php-core && php post-install.php"
],
"post-update-cmd": [
"cd vendor/statsig/statsig-php-core && php post-install.php"
]
}
}
Both require a cron job to fetch configs and flush events:
# Setup chron job / scheduled job to sync config and flush events
*/1 * * * * /usr/bin/php /var/www/example.com/bin/StatsigSyncConfig.php 1>> /dev/null 2>&1
*/1 * * * * /usr/bin/php /var/www/example.com/bin/StatsigFlushEvents.php 1>> /dev/null 2>&1
StatsigUser
// We introduced the user builder pattern
$user_builder = StatsigUserBuilder::withUserID('my_user');
$user_builder->withEmail("example@abc.com");
$user = $user_builder->build()
For usage of big IDLists (>1000 items id list), contact us before using it in php-core
API changes
Key package and class changes
| Feature | Php Core SDK | Legacy Php SDK | Status |
|---|---|---|---|
| Package | statsig/statsig-php-core | statsig | ⚠️ Renamed |
| Import | use Statsig/Statsig | use Statsig/Statsig | Same |
| Options | StatsigOptions | StatsigOptions | ✓ Same |
| User | StatsigUser (With StatsigUserBuilder pattern) | StatsigUser | Construction api changed |
| Initialize | statsig->initialize() | statsig->initialize() | ✓ Same |
| Check Gate | statsig->checkGate() | statsig->checkGate() | ✓ Same |
| Get Config | statsig->getDynamicConfig() | statsig->getConfig() | ⚠️ Naming change |
| Get Experiment | statsig->getExperiment() | statsig->getExperiment() | ✓ Same |
| Get Layer | statsig->getLayer() | statsig->getLayer() | ✓ Same |
| Log Event | statsig->logEvent() | statsig->logEvent() | ✓ Same |
| Shutdown | statsig->shutdown() | statsig->shutdown() | Same |
Behavioral changes
StatsigOptions changes
The table below shows the mapping between legacy SDK options and Server Core SDK options:
| Old Option | New / Notes |
|---|---|
environmentTier | Renamed to be environment |
eventQueueSize | Renamed to be event_logging_max_queue_size |
dataAdapter | Renamed to be specs_adapter |
logging_adapter | Renamed to be event_logging_adapter |
Recommended migration path
Add the new Dependencies
- Add the new SDK package/module and any required platform-specific dependencies for your environment.
- Update import or require statements to reference the new SDK namespace or module.
- Keep the old package in place during local testing; having both running in parallel briefly can help. Alias the new package if needed.
Update Initialization
- Switch to the new initialization syntax. New SDK keys are not required. If you update them, ensure they have the same target apps.
- Use the appropriate builder or configuration pattern for setting options, and migrate the StatsigOptions you use, because some were renamed.
Update User Creation
- Migrate to the new format for creating user objects.
- Use the builder pattern or updated constructor to set user properties if needed.
Update Method Calls
- Start by migrating a few calls, replacing
oldStatsig.getExperiment()withnewStatsig.getExperiment(). - Test your service locally or with existing test patterns to build confidence in the new SDK's operation.
- As you migrate additional calls, update method names that changed (notably,
get_config()toget_dynamic_config()). - After completing the initial migration, use refactoring tools to migrate remaining calls in bulk.
- Start by migrating a few calls, replacing
Test Thoroughly
- Verify that all of your configs are successfully migrated - run your test suites end-to-end.
Remove old SDK
- Remove references to the old SDK, and clean up old initialization and import logic.
Need help?
If you encounter any issues during migration, reach out:
Was this helpful?