Laravel接入Apollo代码示例
发布时间 - 2019-03-02 00:00:00 点击率:次本篇文章给大家带来的内容是关于laravel接入apollo代码示例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
废话不说,直接上代码
'http://10.208.204.46:8161',
'query' => [
'app_id' => 'wuc',
'cluster' => 'default',
'namespace' => 'application',
]
];守护进程
namespace App\Console\Commands\Apollo;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Storage;
class SyncCommand extends Command
{
/**
* The name and signature of the
console command.
*
* @var string
*/
protected $signature = 'ue:apollo:sync';
/**
* The console command description.
*
* @var string
*/
protected $description = '阿波罗同步';
protected $config = [];
protected $url;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
$this->url = config('apollo.server') . '/configs/' . implode('/', array_values(config('apollo.query')));
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->doSync();
}
protected function doSync()
{
$client = new Client(['timeout' => 2.00]);
try {
$response = $client->request('GET', $this->url);
$body = json_decode($response->getBody()->getContents(), true);
$cfg = Arr::get($body, 'configurations', []);
if (!$cfg) {
return true;
}
$cfg = array_map(function ($value) {
if ($row = json_decode($value, true)) {
return $row;
}
return $value;
}, $cfg);
$items = [];
foreach ($cfg as $key => $value) {
data_set($items, $key, $value);
}
foreach ($items as $k => $item) {
$this->line('Saving ['.$k.']');
$this->save($k, $item);
}
} catch (\Exception $ex) {
$this->error($ex->getMessage());
}
}
protected function save($fileName, $item)
{
if(config('apollo.sync.redis', false)){
cache()->tags('apollo')->forever($fileName, $item);
$this->line('Saving To Redis '.$fileName);
}
if(config('apollo.sync.file', false)){
$this->line('Saving To File '.$fileName);
$fileName = 'apollo/' . $fileName . '.php';
ksort($item);
$content = implode("\r\n", [
"put($fileName, $content);
}
$this->line('==================');
}
}
# laravel
# php
# 阿波罗
# 对你
# 有一定
# 给大家
# Illuminate
# Client
# Support
# Command
# Arr
# Storage
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
香港网站服务器数量如何影响SEO优化效果?
如何在万网自助建站中设置域名及备案?
Laravel如何实现RSS订阅源功能_Laravel动态生成网站XML格式订阅内容【教程】
如何快速查询域名建站关键信息?
Laravel如何使用Passport实现OAuth2?(完整配置步骤)
如何续费美橙建站之星域名及服务?
车管所网站制作流程,交警当场开简易程序处罚决定书,在交警网站查询不到怎么办?
Laravel如何处理文件下载请求?(Response示例)
Laravel数据库迁移怎么用_Laravel Migration管理数据库结构的正确姿势
如何确认建站备案号应放置的具体位置?
jQuery中的100个技巧汇总
简历没回改:利用AI润色让你的文字更专业
非常酷的网站设计制作软件,酷培ai教育官方网站?
Linux后台任务运行方法_nohup与&使用技巧【技巧】
悟空识字如何进行跟读录音_悟空识字开启麦克风权限与录音
极客网站有哪些,DoNews、36氪、爱范儿、虎嗅、雷锋网、极客公园这些互联网媒体网站有什么差异?
Laravel怎么实现验证码(Captcha)功能
php8.4header发送头信息失败怎么办_php8.4header函数问题解决【解答】
公司网站制作需要多少钱,找人做公司网站需要多少钱?
微信推文制作网站有哪些,怎么做微信推文,急?
Win10如何卸载预装Edge扩展_Win10卸载Edge扩展教程【方法】
Laravel如何使用Sanctum进行API认证?(SPA实战)
如何快速查询网站的真实建站时间?
laravel服务容器和依赖注入怎么理解_laravel服务容器与依赖注入解析
Laravel如何实现全文搜索功能?(Scout和Algolia示例)
网站建设整体流程解析,建站其实很容易!
如何在沈阳梯子盘古建站优化SEO排名与功能模块?
Laravel怎么配置不同环境的数据库_Laravel本地测试与生产环境动态切换【方法】
Laravel用户密码怎么加密_Laravel Hash门面使用教程
Laravel如何获取当前登录用户信息_Laravel Auth门面使用与Session用户读取【技巧】
香港服务器网站卡顿?如何解决网络延迟与负载问题?
iOS正则表达式验证手机号、邮箱、身份证号等
长沙做网站要多少钱,长沙国安网络怎么样?
高端企业智能建站程序:SEO优化与响应式模板定制开发
浅谈javascript alert和confirm的美化
JS实现鼠标移上去显示图片或微信二维码
EditPlus中的正则表达式 实战(4)
Laravel如何配置Horizon来管理队列?(安装和使用)
简历在线制作网站免费版,如何创建个人简历?
Linux安全能力提升路径_长期防护思维说明【指导】
Laravel如何优雅地处理服务层_在Laravel中使用Service层和Repository层
高性价比服务器租赁——企业级配置与24小时运维服务
zabbix利用python脚本发送报警邮件的方法
Laravel怎么在Controller之外的地方验证数据
edge浏览器无法安装扩展 edge浏览器插件安装失败【解决方法】
如何快速搭建高效简练网站?
Windows驱动无法加载错误解决方法_驱动签名验证失败处理步骤
如何在HTML表单中获取用户输入并结合JavaScript动态控制复利计算循环
个人网站制作流程图片大全,个人网站如何注销?
油猴 教程,油猴搜脚本为什么会网页无法显示?


console command.
*
* @var string
*/
protected $signature = 'ue:apollo:sync';
/**
* The console command description.
*
* @var string
*/
protected $description = '阿波罗同步';
protected $config = [];
protected $url;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
$this->url = config('apollo.server') . '/configs/' . implode('/', array_values(config('apollo.query')));
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->doSync();
}
protected function doSync()
{
$client = new Client(['timeout' => 2.00]);
try {
$response = $client->request('GET', $this->url);
$body = json_decode($response->getBody()->getContents(), true);
$cfg = Arr::get($body, 'configurations', []);
if (!$cfg) {
return true;
}
$cfg = array_map(function ($value) {
if ($row = json_decode($value, true)) {
return $row;
}
return $value;
}, $cfg);
$items = [];
foreach ($cfg as $key => $value) {
data_set($items, $key, $value);
}
foreach ($items as $k => $item) {
$this->line('Saving ['.$k.']');
$this->save($k, $item);
}
} catch (\Exception $ex) {
$this->error($ex->getMessage());
}
}
protected function save($fileName, $item)
{
if(config('apollo.sync.redis', false)){
cache()->tags('apollo')->forever($fileName, $item);
$this->line('Saving To Redis '.$fileName);
}
if(config('apollo.sync.file', false)){
$this->line('Saving To File '.$fileName);
$fileName = 'apollo/' . $fileName . '.php';
ksort($item);
$content = implode("\r\n", [
"put($fileName, $content);
}
$this->line('==================');
}
}