Configuration
Environment
.env:
env
APP_NAME=MyApp
APP_HOST=0.0.0.0
APP_PORT=8080
APP_DEBUG=true
APP_ENV=local
DB_CONNECTION=sqlite
DB_DATABASE=storage/database/app.db
LOG_CHANNEL=stderr
LOG_LEVEL=debugAccess Env
php
$host = env('APP_HOST', '0.0.0.0');
$port = (int) env('APP_PORT', 8080);
$debug = (bool) env('APP_DEBUG', false);env() reads from $_ENV / $_SERVER. If a .env file exists at the project root, it is loaded automatically on boot.
Config Files
config/app.php:
php
<?php
return [
'name' => env('APP_NAME', 'Nexphant'),
'debug' => env('APP_DEBUG', false),
'env' => env('APP_ENV', 'production'),
'host' => env('APP_HOST', '0.0.0.0'),
'port' => (int) env('APP_PORT', 8080),
];Access anywhere via config():
php
use function Nexphant\config;
$name = config('app.name');
$port = config('app.port');Nested keys use dot notation: config('database.connections.default').
Database Config
config/database.php:
php
<?php
return [
'default' => env('DB_CONNECTION', 'sqlite'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', 'storage/database/app.db'),
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => (int) env('DB_PORT', 3306),
'database' => env('DB_DATABASE', 'app'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => (int) env('DB_PORT', 5432),
'database' => env('DB_DATABASE', 'app'),
'username' => env('DB_USERNAME', 'postgres'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
],
],
'pool' => [
'min_connections' => (int) env('DB_POOL_MIN', 2),
'max_connections' => (int) env('DB_POOL_MAX', 20),
'idle_timeout' => (float) env('DB_POOL_IDLE_TIMEOUT', 30.0),
],
];Runtime Config
Pass runtime options to App::create():
php
use Nexphant\App;
$app = App::create([
'base_path' => getcwd(),
'workers' => 4,
'runtime_mode' => 'throughput', // 'throughput' | 'balanced' | 'latency'
'event_loop' => 'auto', // 'auto' | 'ev' | 'event' | 'native'
'socket_driver' => 'native',
'max_accept_per_tick' => 32,
'keep_alive_timeout' => 30,
'supervisor' => true,
'metrics' => true,
]);Or fluent-style after creation:
php
$app->workers(4)
->runtimeMode('throughput')
->eventLoop('event')
->maxAcceptPerTick(32)
->supervisor(true);Runtime Modes
| Mode | Description |
|---|---|
throughput | Maximise requests/sec. Accepts more connections per tick. Best for APIs. |
balanced | Default. Balances throughput and latency. |
latency | Minimise response time. Accepts fewer connections per tick. Best for real-time. |
Config Cache
Cache all config files into a single PHP array for faster boot:
bash
php nexphant cache:configIn production, always cache config and set opcache.validate_timestamps=0 in php.ini.
