Download the PHP package sodaho/env-loader without Composer
On this page you can find all versions of the php package sodaho/env-loader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package env-loader
env-loader
Lightweight .env file loader for PHP. Zero dependencies.
Why This Library?
There are established .env loaders for PHP, most notably vlucas/phpdotenv. This library exists because we needed something simpler:
- Zero dependencies — Nothing to install besides this package.
- Thread-safe by design — Only writes to
$_ENV. Noputenv()/getenv(), which are not thread-safe in async runtimes (Swoole, RoadRunner, FrankenPHP). - No magic — No variable expansion (
${VAR}), no multiline values, no interpreted escape sequences (\n,\t). What you write is what you get. - Minimal footprint — Easy to audit, easy to understand.
If you need variable expansion, multiline values, or getenv() support, use phpdotenv instead.
Installation
Usage
Basic Usage
Options
Parse Without Loading
Supported .env Syntax
Exceptions
All exceptions extend EnvLoaderException for easy catching:
| Exception | When |
|---|---|
FileNotFoundException |
File does not exist or is a directory |
FileNotReadableException |
File exists but not readable |
InvalidKeyException |
Key has invalid format (e.g. 123KEY, MY-KEY) |
UnterminatedQuoteException |
Quoted value missing closing quote |
MissingRequiredKeyException |
Required key missing after loading |
Key Naming Rules
Valid keys must:
- Start with a letter or underscore
- Contain only letters, numbers, and underscores
Why $_ENV Only?
This library intentionally writes only to $_ENV, not putenv() or $_SERVER.
Reason: Thread Safety
putenv() and getenv() are not thread-safe. In modern PHP runtimes like:
- Swoole
- RoadRunner
- FrankenPHP
- ReactPHP
...concurrent requests can overwrite each other's environment variables, causing hard-to-debug race conditions.
$_ENV is process-local and safe. Use $_ENV['KEY'] instead of getenv('KEY') in your application.
When to Use
- Development environments
- Shared hosting where system ENV is not available
- Simple projects without framework
- Modern async PHP (Swoole, RoadRunner, FrankenPHP)
When NOT to Use
- Production with proper system ENV configuration
- When you need variable expansion (
${OTHER_VAR}) - When you need multiline values
- When you must support legacy code using
getenv()
Requirements
- PHP ^8.2
Acknowledgments
Parts of this project (refactoring, documentation, code review) were developed with AI assistance (Claude).
License
MIT