kislayphp/config
Composer 安装命令:
pie install kislayphp/config
包简介
High-performance C++ PHP extension providing dynamic configuration management for PHP microservices
关键字:
README 文档
README
kislayphp/config is a centralized configuration service and runtime client for multi-node PHP services.
Phase 1 adds:
- standalone config server
- runtime client bootstrap with local cache support
- layered config resolution for environment, project, service, and node scopes
- local file, environment variable, and runtime overrides
This package is part of the KislayPHP ecosystem.
Installation
pie install kislayphp/config
Enable the extension:
extension=kislayphp_config.so
Quick Start
1. Start a config server
<?php $server = new Kislay\Config\Server(); $server->listen('0.0.0.0', 9011); $server->setGlobal([ 'app' => ['name' => 'commerce-platform'], 'db' => ['port' => 3306], ]); $server->setEnvironment('prod', [ 'app' => ['debug' => false], ]); $server->setProject('commerce', [ 'log' => ['level' => 'warn'], ]); $server->setService('commerce', 'order-service', [ 'db' => ['name' => 'orders'], 'gateway' => ['timeout_ms' => 1200], ]); $server->setNode('commerce', 'order-service', 'order-1', [ 'metrics' => ['enabled' => false], ]); $server->run();
2. Load config inside a service
<?php use Kislay\Config\Config; Config::boot([ 'server' => 'http://127.0.0.1:9011', 'environment' => 'prod', 'project' => 'commerce', 'service' => 'order-service', 'node' => 'order-1', 'cache_file' => '/tmp/order-service-config.json', ]); $dbName = Config::getString('db.name'); $timeout = Config::getInt('gateway.timeout_ms', 1000); $debug = Config::getBool('app.debug', true);
3. Add local overrides
<?php Config::loadLocal('/etc/kislay/order-service.local.json'); Config::setOverride('gateway.timeout_ms', 1500);
Resolution Order
Config is merged in this order:
- global
- environment
- project
- service
- node
- local file override
- environment variable override
- runtime override
Environment variables use KISLAY_CFG_ by default.
Example:
export KISLAY_CFG_DB__HOST=127.0.0.1 export KISLAY_CFG_LOG__LEVEL=error
Double underscore becomes . in the final config key.
Public API
Kislay\Config\Config
Config::boot(array $options): bool Config::loadLocal(string $path): bool Config::refresh(): bool Config::setOverride(string $key, mixed $value): bool Config::has(string $key): bool Config::get(string $key, mixed $default = null): mixed Config::getString(string $key, ?string $default = null): ?string Config::getInt(string $key, int $default = 0): int Config::getBool(string $key, bool $default = false): bool Config::getArray(string $key, array $default = []): array Config::all(): array Config::version(): string Config::checksum(): string
Kislay\Config\Server
$server = new Kislay\Config\Server(['host' => '127.0.0.1', 'port' => 9011]); $server->listen('0.0.0.0', 9011); $server->setGlobal(array $config): bool; $server->setEnvironment(string $environment, array $config): bool; $server->setProject(string $project, array $config): bool; $server->setService(string $project, string $service, array $config): bool; $server->setNode(string $project, string $service, string $node, array $config): bool; $server->resolve(?string $environment = null, ?string $project = null, ?string $service = null, ?string $node = null): array; $server->version(): string; $server->save(string $path): bool; $server->load(string $path): bool; $server->run(): bool; $server->stop(): bool;
Kislay\Config\ConfigClient
Compatibility client retained for simple in-memory or delegated use:
$client = new Kislay\Config\ConfigClient(); $client->set('db.host', '127.0.0.1'); $client->get('db.host'); $client->all();
HTTP Endpoints
The standalone server exposes:
GET /healthGET /v1/config/versionGET /v1/config/resolve?environment=prod&project=commerce&service=order-service&node=order-1PUT /v1/config/globalPUT /v1/config/environments/{environment}PUT /v1/config/projects/{project}PUT /v1/config/projects/{project}/services/{service}PUT /v1/config/projects/{project}/services/{service}/nodes/{node}
PUT bodies accept JSON objects. Nested objects are flattened into dotted keys inside the runtime snapshot.
Production Notes
Current Phase 1 behavior:
- runtime refresh is explicit with
Config::refresh() cache_filestores the last successful remote snapshot- array values are stored as JSON and returned through
getArray() all()returns the resolved flat dotted-key map
Not in Phase 1 yet:
- background polling thread
- auth tokens / TLS
- config revision history / rollback API
- clustered config servers
Example
See /tmp/kislayphp_config_phase1/example.php for a minimal server/client walkthrough.
License
kislayphp/config 适用场景与选型建议
kislayphp/config 是一款 基于 Shell 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「microservices」 「php-config」 「php-extension」 「dynamic-config」 「php-echo-system」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kislayphp/config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kislayphp/config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kislayphp/config 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The Listener component of the RabbitEvents library.
The Publisher component of the RabbitEvents package.
Laravel common
Laravel support for additional blueprint methods
Laravel comment system
Laravel support for GELF logging
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 41
- 依赖项目数: 0
- 推荐数: 7
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-02-15