本篇文章给大家带来的内容是关于Laravel接入Apollo代码示例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
废话不说,直接上代码
<?php /** * Created by PhpStorm. * User: dehua * Date: 2019/3/1 * Time: 14:17 */ return [ 'server' => '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", [ "<?php", "return", var_export($item, true) . ';' ]); Storage::disk('config')->put($fileName, $content); } $this->line('=================='); } }
以上是Laravel接入Apollo代码示例的详细内容。更多信息请关注PHP中文网其他相关文章!

Laravel10IntroducessEveralKeyFeatUrestHatenHanceWebDevelopment.1)LazyCollectionsAllyCollefficeProcesingOflargeFlargedAtasetSwithSwithOutloadingAllRecordSintomeMemory.2)the Make:Model Model Moged-and-Mogration'ArtisanCommandSancancMommandSimplififieScreatingModeltigation.3)

laravelmigrationssshouldbeusedbecausetheystreamlinedeplupment,nesurecresistencyAcrossenviments和simplifyCollaborationAndDeployment.1)shemallogragrammatonofdatabaseschemachanges,ReeducingErrors.2)MigrigationScanBeverCanbeverSionConconconconcontrollin.2)

SoftDeletesinLaravelimpactperformancebycomplicatingqueriesandincreasingstorageneeds.Tomitigatetheseissues:1)Indexthedeleted_atcolumntospeedupqueries,2)Useeagerloadingtoreducequerycount,and3)Regularlycleanupsoft-deletedrecordstomaintaindatabaseefficie

Laravelmigrationsarebeneficialforversioncontrol,collaboration,andpromotinggooddevelopmentpractices.1)Theyallowtrackingandrollingbackdatabasechanges.2)Migrationsensureteammembers'schemasstaysynchronized.3)Theyencouragethoughtfuldatabasedesignandeasyre

Laravel的软删除功能通过标记记录而非实际删除来保护数据。1)在模型中添加SoftDeletestrait和deleted_at字段。2)使用delete()方法标记删除,使用restore()方法恢复。3)查询时使用withTrashed()或onlyTrashed()包含软删除记录。4)定期清理超过一定时间的软删除记录以优化性能。

laravelmigrationSareversionControlfordatabaseschemas,允许Roducibleandreversiblechanges.tousethem:1)creatighatsanmake:迁移',2)定义chemachangesinthe'up()

Laravelmigrationsmayfailtorollbackduetodataintegrityissues,foreignkeyconstraints,orirreversibleactions.1)Dataintegrityissuescanoccurifamigrationaddsdatathatcan'tbeundone,likeacolumnwithadefaultvalue.2)Foreignkeyconstraintscanpreventrollbacksifrelatio


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

记事本++7.3.1
好用且免费的代码编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。