Feature flags for PHP — simple cURL integration for any PHP application
Sign up at flagbit.anethoth.com to get your SDK key. The free tier includes 1,000 evaluations/day.
# No dependencies needed — uses built-in cURL
<?php
function get_flag(string $flag_key, array $context = []): bool {
$ch = curl_init('https://flagbit.anethoth.com/api/v1/evaluate');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'X-SDK-Key: ' . getenv('FLAGBIT_SDK_KEY'),
],
CURLOPT_POSTFIELDS => json_encode([
'flag_key' => $flag_key,
'context' => $context ?: new stdClass(),
]),
]);
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) return false;
$data = json_decode($response, true);
return $data['value'] ?? false;
}
// With APCu caching
function get_flag_cached(string $flag_key, array $context = [], int $ttl = 60): bool {
$cache_key = "flag:{$flag_key}:" . md5(json_encode($context));
$cached = apcu_fetch($cache_key, $success);
if ($success) return $cached;
$value = get_flag($flag_key, $context);
apcu_store($cache_key, $value, $ttl);
return $value;
}
// WordPress integration
function flagbit_shortcode($atts) {
$flag_key = $atts['flag'] ?? '';
if (get_flag_cached($flag_key, ['user_id' => get_current_user_id()])) {
return $atts['content'] ?? '';
}
return '';
}
add_shortcode('feature', 'flagbit_shortcode');
// Symfony controller
class ProductController extends AbstractController {
#[Route('/products')]
public function list(): Response {
$user = $this->getUser();
$ctx = $user ? ['user_id' => (string)$user->getId()] : [];
if (get_flag_cached('new-product-list', $ctx)) {
return $this->render('product/list_v2.html.twig');
}
return $this->render('product/list.html.twig');
}
}
Gate plugin features behind flags — enable for specific users or roles without code changes.
A/B test checkout flows, product page layouts, or pricing displays.
Gradually migrate from legacy PHP to a modern framework — flag controls which code path runs.
Route API requests to v1 or v2 handlers based on feature flags and user context.
Define flags in your FlagBit dashboard with targeting rules and rollout percentages.
Call the evaluate endpoint from your PHP app with user context for targeted rollouts.
Enable, disable, or adjust rollouts in real-time. No redeployment needed.
Yes — the cURL code works with PHP 7.4+. No modern PHP features required.
Use file-based caching, Redis, or Memcached. Any cache that supports TTL will work.
Yes — the shortcode example above lets you feature-gate content in posts and pages.
FlagBit works anywhere cURL is available — shared hosting, VPS, or managed platforms.
Free tier includes 1 project, 10 flags, and 1,000 evaluations/day. No credit card required.
Get Your Free API Key