PHPackages                             beatlabs/load - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. beatlabs/load

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

beatlabs/load
=============

PHP library for config loading

v1.1.1(4y ago)53Apache-2.0PHPPHP &gt;=7.2

Since Sep 9Pushed 4y ago2 watchersCompare

[ Source](https://github.com/beatlabs/load)[ Packagist](https://packagist.org/packages/beatlabs/load)[ RSS](/packages/beatlabs-load/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

LOAD [![Build Status](https://camo.githubusercontent.com/85874f8cb1083f936a801bfcf3b9954a93ef065c05f6fc8ccc9b55fe5e58a4a5/68747470733a2f2f7472617669732d63692e636f6d2f74617869626561742f6c6f61642e7376673f746f6b656e3d38636270674c4e474278726d7946717a79343254266272616e63683d6d6173746572)](https://travis-ci.com/taxibeat/load)
=================================================================================================================================================================================================================================================================================================================================

[](#load-)

**LOAD** is a PHP library for configuration loading to **APCu**

Sources
-------

[](#sources)

Available sources for configuration loading are:

- PHP file
- Consul
- Environment variables

Install
-------

[](#install)

You can install `load` using [Composer](https://getcomposer.org/) by running the following:

`composer require beatlabs/load`

Usage
-----

[](#usage)

PHP file:

You can read a `PHP` file that returns an array.

For example with `config.php`:

```
return [
    'var' => [
        'sub-var' => 'sub-val',
        'val',
    ]
];
```

You can use the following:

```
$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');
```

Consul (Default server *localhost:8500*):

```
$loader = new BeatLabs\Load\Loader\ConsulLoader();
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');
```

Consul (Custom server *myhost:8000* with root path "services/my-service"):

```
// You can get all available options here: https://docs.guzzlephp.org/en/6.5/quickstart.html#creating-a-client
$options = [
    "base_uri" => "myhost:8000"
];
$loader = new BeatLabs\Load\Loader\ConsulLoader('services/my-service', $options);

$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');
```

Environment variables:

You can have a prefix for environment variables so that you only include environment variables that start with that prefix. That gives the ability to load only what needed instead of entire environment as a configuration.

```
// Set variable
$loader = new BeatLabs\Load\Loader\EnvLoader('PREFIX_'); // Define environment variables prefix to be loaded
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val = $config->get('var');
```

Multiple loaders:

```
$consulLoader = new BeatLabs\Load\Loader\ConsulLoader();
$fileLoader = new BeatLabs\Load\Loader\PHPLoader('config.php');
$envLoader = new BeatLabs\Load\Loader\EnvLoader('PREFIX_');
$config = new BeatLabs\Load\Config([$consulLoader, $fileLoader, $envLoader]);
$config->load();

// Get configuration values
$val = $config->get('var');
```

Loaders are executed in the order they are defined. Each loader will override any configuration loaded from previous loaders.

Custom cache
------------

[](#custom-cache)

By default, `load` uses `APCu` to cache configuration, but you can use your own cache (ex. Redis, Memcache etc.) by implementing the `BeatLabs\Load\Interfaces\Cache` interface and set it to `Config` constructor.

For example:

```
$cache = new CustomCache();
$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader], $cache);
$config->load();
```

Configuration flattening
------------------------

[](#configuration-flattening)

Configuration values that have nested sub-values are flattened and can be fetched without further process.

For example:

`config.php`

```
return [
    'var' => [
        'sub-var' => 'sub-val',
        'val',
    ]
];
```

Will behave like this:

```
$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader]);
$config->load();

// Get configuration values
$val1 = $config->get('var'); // $val = ['sub-var' => 'sub-val, 'val']
$val2 = $config->get('var.sub-var'); // $val = 'sub-val'
```

The default separator is `.`, but you can set your own at `Config` constructor.

For example:

```
$loader = new BeatLabs\Load\Loader\PHPLoader('config.php'); // Config file
$config = new BeatLabs\Load\Config([$loader], null, '_');
$config->load();

// Get configuration values
$val1 = $config->get('var'); // $val = ['sub-var' => 'sub-val, 'val']
$val2 = $config->get('var_sub-var'); // $val = 'sub-val'
```

Reload configuration
--------------------

[](#reload-configuration)

Configuration can be reloaded by sending `SIGUSR2` to PHP running process for `CLI` scripts and in `php-fpm` master process for `HTTP` scripts.

Reloading can also be invoked in code by using the following code:

```
$config->reload();
```

How to Contribute
-----------------

[](#how-to-contribute)

See [Contribution Guidelines](CONTRIBUTE.md)

Code of conduct
---------------

[](#code-of-conduct)

Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project and its community you agree to abide by those terms.

Changelog
---------

[](#changelog)

You can see changelog [here](CHANGELOG.md)

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1749d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/94088cb304efa0fd1ea8961f873768e7286e11588c1ec68eef24722995434a08?d=identicon)[kostasxx](/maintainers/kostasxx)

---

Top Contributors

[![c0nstantx](https://avatars.githubusercontent.com/u/2987632?v=4)](https://github.com/c0nstantx "c0nstantx (7 commits)")[![mantzas](https://avatars.githubusercontent.com/u/605434?v=4)](https://github.com/mantzas "mantzas (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/beatlabs-load/health.svg)

```
[![Health](https://phpackages.com/badges/beatlabs-load/health.svg)](https://phpackages.com/packages/beatlabs-load)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
