########## 数据库配置 ########## database: master: # 主库配置 host: 192.168.1.1 # 主机地址 port: 3306 # 端口号 user: master # 账号 pwd : master123456 # 密码 slave: # 从库配置 host: 192.168.2.2 port: 3306 user: slave pwd : slave123456 ########## Redis配置 ########## redis: host: 192.168.1.1 # 主机地址 port: 6379 # 端口号 ########## RSA配置 ########## rsa: public_key : '/opt/rsa/rsa_public_key.pem' # 公钥文件路径 private_key: '/opt/rsa/rsa_private_key.pem' # 私钥文件路径
<?php $conf = yaml_parse_file(__DIR__ . '/demo.conf'); print_r($conf); // 获取所有配置 print_r($conf['database']['slave']); // 获取指定配置
<?php require_once __DIR__ . '/Yaml/vendor/autoload.php'; use Symfony\Component\Yaml\Exception\ParseException; use Symfony\Component\Yaml\Yaml; try { $conf = Yaml::parseFile('./demo.conf'); print_r($conf); // 获取所有配置 print_r($conf['database']['slave']); // 获取指定配置 } catch (ParseException $e) { echo $e->getMessage(); }
Copyright © 2024 码农人生. All Rights Reserved