totoro / apollo-config
1.3.0
2018-08-23 05:38 UTC
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ^6.3
- predis/predis: ^1.1
README
- 方便程序快速获取配置参数
- 支持
redis、SHM、file存储方式 SHM只支持linux下使用- Laravel 5.5+
安装
composer require totoro/apollo-config
在 Laravel
- 在
config/app.php
'providers' => [
...
...
Totoro\Apollo\ApolloServiceProvider::class,
]
在 Lumen
- 在
bootstrap/app.php
$app->configure('apollo');
$app->register(Totoro\Apollo\ApolloServiceProvider::class);
用法
//值是否存在
app('apollo')->has($key)
//获取某个值
app('apollo')->get($key)
//获取所有值
app('apollo')->all()
重要说明
APOLLO_DRIVER 为 file 时只需要简单配置
配置
- 执行
php artisan apollo:publish-config将配置文件发布到 (config/apollo.php)
当 APOLLO_DRIVER设置为 redis 或者 shm 时
- 配置文件根据部署的参数设置好
- 执行
php artisan apollo:publish-consul将注册中心的服务地址发布到存储库中 - 执行
php artisan apollo:publish-component将配置中心参数发布到存储库中 - 可以执行
php artisan apollo:clear-apollo清空当前存储库
定时任务
在 app/Console/Kerner.php中添加定时任务调用
protected $commands = [
...
...
PublishConsulCommand::class,
PublishComponentCommand::class
];
protected function schedule(Schedule $schedule)
{
...
...
//更新注册中心服务地址
$schedule->command(PublishConsulCommand::class)->everyMinute();
//更新配置中心单当前服务参数
$schedule->command(PublishComponentCommand::class)->everyMinute();
}
- 启动调度器
* * * * * php /your-project-path/laravel/artisan schedule:run >> /dev/null 2>&1
当 APOLLO_DRIVER设置为 file 时
.env中设置配置文件的路径,默认/etc/xultra/php_conf,当然也可以直接在config/apollo.php中设置
APOLLO_DRIVER=file
APOLLO_CONF=/etc/xultra/php_conf
- 在配置文件
/etc/xultra/php_conf中设置参数
xu-billing=http://127.0.0.1:1000
xu-audit=http://127.0.0.1000