Skip to content

Multiple Devices / Servers

BioTime is constructed from a Config instance, not global state — so talking to more than one device or BioTime server just means constructing more than one BioTime instance, each with its own explicit Config.

php
use BioTime\BioTime;
use BioTime\Config;

$hq = new BioTime(Config::fromArray([
    'ip'              => '192.168.1.50',
    'username'        => 'admin',
    'password'        => 'secret',
    'token_cache_key' => 'biotime_token_hq',
]));

$branch = new BioTime(Config::fromArray([
    'ip'              => '192.168.10.50',
    'username'        => 'admin',
    'password'        => 'secret2',
    'token_cache_key' => 'biotime_token_branch',
]));

$hqEmployees     = $hq->employees()->all();
$branchEmployees = $branch->employees()->all();

Give each device its own token cache key

If you share a single PSR-16 cache backend (e.g. one Redis instance) across devices, set a distinct token_cache_key for each Config — otherwise every device's token would overwrite the same cache entry. This is why the example above sets token_cache_key explicitly for both instances.

Laravel: one binding per device

Laravel's default service provider registers exactly one BioTime singleton, resolved from config/biotime.php/env. For multiple devices in a Laravel app, register additional bindings yourself in your own service provider, giving each a distinct name:

php
$this->app->singleton('biotime.hq', fn () => new BioTime(Config::fromArray([
    'ip' => '192.168.1.50', /* ... */ 'token_cache_key' => 'biotime_token_hq',
])));

$this->app->singleton('biotime.branch', fn () => new BioTime(Config::fromArray([
    'ip' => '192.168.10.50', /* ... */ 'token_cache_key' => 'biotime_token_branch',
])));
php
$hq = app('biotime.hq');

Distributed under the MIT License.