PHP code example of woodynew / alicloud-config-monitor

1. Go to this page and download the library: Download woodynew/alicloud-config-monitor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

woodynew / alicloud-config-monitor example snippets



/**
 * 阿里云 MES nacos 配置监控命令
 * https://packagist.org/packages/verystar/aliyun-acm
 */
Artisan::command('alicloud-mes:listenconfig', function(){
    $this->info('阿里云MES配置监控');
    
    //下面两个路径如果不使用默认,则需要确保存在
    $changeToEnvFile = base_path('.env_test');      //env文件路径(确定没问题后修改为 .env)
    $snapshotPath = storage_path();                 //配置快照存储路径
    
    //实例化,并启动监听
    try {
        $monitorInstance  = app(\Alicloud\ConfigMonitor\MonitorHandle::class, [
            'snapshotPath'  => $snapshotPath,
            'changeToEnvFile' => $changeToEnvFile,
            'pullingSenonds' => 30,
            'env'           => env('APP_ENV'),
        ]);
        $monitorInstance->listenNotify();  //开启监控
    } catch(\Exception $err) {
        $errorinfo = $err->getMessage();
        \Illuminate\Support\Facades\Log::error($errorinfo,[
            //'storage_path' => $snapshotPath,
            //'env_test' => $changeToEnvFile
        ]);
    }
    
})->describe('阿里云MES配置监控');



    JZTech-xxx: huangwh$ php artisan alicloud-mes:listenconfig
    阿里云MES配置监控
    [2022-01-07 11:42:48] nacos-client.INFO: 配置监听中,长轮询时间为10秒 ...   [] []
    [2022-01-07 11:42:48] nacos-client.INFO: 监听到配置有变更,已经更新到本地ENV文件...   [] []
    [2022-01-07 11:42:48] nacos-client.INFO: listener loop count: 1 [] []
    [2022-01-07 11:42:58] nacos-client.INFO: 配置无变化,监听中...  [] []
    [2022-01-07 11:42:58] nacos-client.INFO: listener loop count: 2 [] []
    ...