All Projects → neatlife → php-nacos

neatlife / php-nacos

Licence: MIT license
阿里巴巴nacos配置中心-PHP客户端

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-nacos

Nacos
an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
Stars: ✭ 20,691 (+12289.82%)
Mutual labels:  config, configuration-management, service-mesh, alibaba, istio, nacos
juno-agent
juno-agent
Stars: ✭ 46 (-72.46%)
Mutual labels:  config, configuration-management, service-mesh
Juno
Juno 译名朱诺。这个名字来源于古罗马神话中的众神之母。它是斗鱼的微服务管理系统, 如同众神之母一样守护着所有微服务的系统。
Stars: ✭ 285 (+70.66%)
Mutual labels:  config, configuration-management, service-mesh
istio-talk
A talk on Istio and related demos
Stars: ✭ 11 (-93.41%)
Mutual labels:  service-mesh, istio
redconf
sync config from redis or others storage while the config values changed
Stars: ✭ 12 (-92.81%)
Mutual labels:  config, configuration-management
advanced-istio-service-mesh-workshop
Advanced Istio Service Mesh Workshop
Stars: ✭ 28 (-83.23%)
Mutual labels:  service-mesh, istio
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (-1.2%)
Mutual labels:  config, configuration-management
sitri
Sitri - powerful settings & configs for python
Stars: ✭ 20 (-88.02%)
Mutual labels:  config, configuration-management
DazzleConf
Incredible configuration library
Stars: ✭ 34 (-79.64%)
Mutual labels:  config, configuration-management
cf-k8s-networking
building a cloud foundry without gorouter....
Stars: ✭ 33 (-80.24%)
Mutual labels:  service-mesh, istio
libconfini
Yet another INI parser
Stars: ✭ 106 (-36.53%)
Mutual labels:  config, configuration-management
superconfig
Access environment variables. Also includes presence validation, type coercion and default values.
Stars: ✭ 33 (-80.24%)
Mutual labels:  config, configuration-management
service-mesh-patterns
Templates of service mesh configurations imbued with best practices.
Stars: ✭ 68 (-59.28%)
Mutual labels:  service-mesh, istio
ini
📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载
Stars: ✭ 72 (-56.89%)
Mutual labels:  config, configuration-management
shopping-cart-k8s
Service Mesh patterns for Microservices
Stars: ✭ 57 (-65.87%)
Mutual labels:  service-mesh, istio
meshery
Meshery, the cloud native manager
Stars: ✭ 1,587 (+850.3%)
Mutual labels:  service-mesh, istio
book-source-code
Accompanying source code for Istio in Action (Manning)
Stars: ✭ 175 (+4.79%)
Mutual labels:  service-mesh, istio
grpc-web-istio-demo
A demo for showcasing gRPC-Web with Istio.
Stars: ✭ 67 (-59.88%)
Mutual labels:  service-mesh, istio
Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+1010.78%)
Mutual labels:  config, configuration-management
Config
Easiest way to add multi-environment yaml settings to Rails, Sinatra, Pandrino and other Ruby projects.
Stars: ✭ 1,821 (+990.42%)
Mutual labels:  config, configuration-management

阿里巴巴nacos配置中心-PHP客户端

Nacos配置中心的PHP客户端,更多关于Nacos配置中心的介绍,可以查看Nacos配置中心Wiki

特性

  1. 容错兜底
  2. 容易上手
  3. 技术支持,有问题可加作者微信: suxiaolinKing

开发计划

composer安装

composer require alibaba/nacos

使用crontab拉取配置文件

定时1分钟拉取一次

*/1 */1 * * * php path/to/cron.php
# cron.php
Nacos::init(
    "http://127.0.0.1:8848/",
    "dev",
    "LARAVEL",
    "DEFAULT_GROUP",
    ""
)->runOnce();

拉取到的配置文件路径:当前工作目录/nacos/config/dev_nacos/snapshot/LARAVEL

配置文件保存的工作目录可以通过下面命令修改

NacosConfig::setSnapshotPath("指定存放配置文件的目录路径");

长轮询拉取配置文件

Nacos::init(
    "http://127.0.0.1:8848/",
    "dev",
    "LARAVEL",
    "DEFAULT_GROUP",
    ""
)->listener();

事件监听器

GetConfigRequestErrorListener::add(function($config) {
    if (!$config->getConfig()) {
        echo "获取配置异常, 配置为空,下面进行自定义逻辑处理" . PHP_EOL;
        // 设置是否修改配置文件内容,如果修改成true,这里设置的配置文件内容将是最终获取到的配置文件
        $config->setChanged(true);
        $config->setConfig("hello");
    }
});

配置兜底方案

将兜底的配置文件放入下面的路径里

如果有给$tenant设置值,文件路径这样计算

工作目录/nacos/config/{$env}_nacos/config-data-{$tenant}/{$dataId}

否则

工作目录/nacos/config/{$env}_nacos/config-data/{$dataId}

nacos会在无法从配置中心查询配置文件时将读取上面的配置文件

Dummy模式(本地开发不走配置中心)

配置环境变量NACOS_ENV=local再启动项目

export NACOS_ENV=local

贡献者

Thanks goes to these wonderful people:


fatrbaby

📖

TELstatic

📖

wujunze

📖

ifcute

📖

RobberPhex

📖

Contributions of any kind are welcome!

感谢nacos团队赠送的纪念杯

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].