PHP
Installation
Install the tggl/client
package:
composer require tggl/client
Quick start
Instantiate a client with your API key and call evalContext
to evaluate a context. A single API call evaluating all flags is performed, making all subsequent flag checking methods extremely fast.
This means that you do not need to cache results of isActive and get since they do not trigger an API call, they simply look up the data in the already fetched response.
Evaluating contexts in batches
If you have multiple contexts to evaluate at once, you can batch your calls in a single HTTP request which is much more performant:
isActive
vs get
By design, you have no way of telling apart an inactive flag, a non-existing flag, a deleted flag, or a network error. This design choice prevents anything from breaking your app by just deleting a flag, messing up the API key rotation, or any other unforeseen event, it will simply consider any flag to be inactive.
Do not use get
if you simply want to know if a flag is active or not, use isActive
instead.
get
gives you the value of an active flag, and this value may be "falsy" (null, false, 0, or empty string), leading to unexpected behaviors:
Evaluate flags locally
It is possible to evaluate flags locally on the server but not recommended unless you have performance issues evaluating flags at a high frequency. Evaluating flags locally forces you to maintain the copy of flags configuration up to date and might be a source of issues.
Make sure to add the right keys to your context to be perfectly consistent with the Tggl API.
When evaluating flags locally it is your responsibility to keep the configuration up to date by calling fetchConfig
when needed. You can use webhooks to be notified when the configuration changes.
You can cache the configuration and instantiate the client with the cached version, so you don't need to call fetchConfig: