Download the PHP package greenflags/greenflags-php without Composer

On this page you can find all versions of the php package greenflags/greenflags-php. 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 greenflags-php

greenflags/greenflags-php

Official PHP SDK for consuming GreenFlags feature flags from any PHP application: Laravel, Symfony, WordPress plugins, plain PHP.

Zero dependencies — PHP standard library only (streams + JSON). Built to minimize billable requests even in request-scoped PHP-FPM, via a pluggable snapshot cache: at most one network read per TTL per server, no matter how many requests you handle.

Status: 0.1.0. Full changelog in CHANGELOG.md.


Table of Contents


Why it exists

GreenFlags exposes a read endpoint (GET /v1/flags) where every 2xx response counts as a billable read. A naive integration that fetches flags on every request can generate thousands of unnecessary reads.

The PHP-FPM problem (and the fix)

In Node/Go/Python, an in-memory snapshot survives between requests. Classic PHP-FPM tears the process down after every request — in-memory caching alone would still pay one read per request.

This SDK fixes that with a SnapshotCacheInterface (two methods: get/set a JSON string with a TTL) plus the sync() method:

  1. sync(60) checks the cache. Fresh snapshot there? Zero network calls.
  2. Cache empty or expired? One GET /v1/flags (1 billable read), stored back with the TTL.

Result: at most one read per minute per server (with ttl=60), whether you serve 10 or 10,000 requests. Adapters included: ApcuCache (shared across FPM workers) and InMemoryCache (Octane/workers/tests). A Redis or Laravel Cache adapter is ~5 lines (see the recipe below).

Features

Requirements

Quick Start

Usage Guide

Ground rules

Laravel Recipe

With Redis as Laravel's cache driver, your entire fleet shares one snapshot: one billable read per minute total.

WordPress / WooCommerce Recipe

WordPress ships its own cache primitive — transients — which maps directly onto SnapshotCacheInterface. Drop this in a small plugin (or wp-content/mu-plugins/greenflags.php):

Use it anywhere in your theme or WooCommerce hooks:

Or expose a shortcode so editors can gate content from the block editor:

Define the token in wp-config.php (never in the database or a template):

With an object cache plugin (Redis/Memcached), transients are shared across all PHP workers — one billable read per minute for the whole site.

API Reference

new Client(...)

Parameter Type Description
url string API base URL, trailing slash optional.
apiToken string Environment-scoped token (gf_...).
coordinates ?Coordinates Optional end-user location for geofence evaluation.
cache ?SnapshotCacheInterface Optional snapshot cache — strongly recommended in PHP-FPM.
httpGet ?callable Optional HTTP layer: (string $url, array $headers): array{int, string}.

Methods

Method Signature Description
sync (int $ttlSeconds = 60): void Cache-first load: 0 requests on hit, 1 billable read on miss (stored back with the TTL).
refresh (int $cacheTtlSeconds = 60): void Forces 1 request, replaces the snapshot, updates the cache.
getSnapshot (): array<string, Flag> Evaluated snapshot, keyed by flag key. Local read.
getAllFlags (): list<Flag> Every evaluated flag. Local read.
getFlag (string $key, mixed $default = null): mixed Evaluated value or $default. Never throws for missing flags.
isEnabled (string $key): bool true only when the flag exists and evaluates to true.
setCoordinates (?Coordinates): void Sets/clears the location for geofence evaluation. No network.

Geofence

Flags may carry a geofence (latitude/longitude/radius, configured in the dashboard). With coordinates set, each geofenced flag is evaluated locally:

Fail-open, by design: a geofence is not a security boundary.

Error Handling

errorCode status Cause
INVALID_TOKEN 401 Token missing, invalid, or revoked
QUOTA_EXCEEDED 429 Monthly read quota exhausted
BILLING_NO_SUBSCRIPTION 429 The workspace has no active subscription
BILLING_CANCELED 429 Subscription canceled
BILLING_PAST_DUE 429 Payment past due
BILLING_TRIAL_EXPIRED 429 Trial expired
BILLING_LIMIT_REACHED 429 Billing limit reached
NETWORK_ERROR 0 The request failed before a response was received
PARSE_ERROR response status Body wasn't valid JSON, or was missing data.flags
REQUEST_ERROR response status Non-2xx response with no parseable error code

Read methods never throw any of these — they're always local.

Billing Model

Only refresh() — or a sync() cache miss — makes a request; every 2xx counts as one billable read. With sync(60) + a shared cache (APCu per server, Redis per fleet), your cost ceiling is 1 read per TTL per cache, independent of traffic.

Development

Versioning

Semver, while in 0.x: MINOR can include API changes, PATCH are fixes. Version-by-version detail in CHANGELOG.md.

Related

Percentage rollout & variants

Server processes serve many users, so identity is per call — resolve rollout/variants for a specific end user with:

getFlag (no user) keeps returning the raw value (fail-open). Bucketing is deterministic and identical across every GreenFlags SDK and the server (docs/rollout-hash-spec.md).


All versions of greenflags-php with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-json Version *
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 greenflags/greenflags-php contains the following files

Loading the files please wait ...