欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP實(shí)現(xiàn)的redis主從數(shù)據(jù)庫狀態(tài)檢測功能示例

 更新時(shí)間:2017年07月20日 10:13:25   作者:3wlog  
這篇文章主要介紹了PHP實(shí)現(xiàn)的redis主從數(shù)據(jù)庫狀態(tài)檢測功能,涉及php針對多個(gè)redis主從數(shù)據(jù)庫的連接、檢測、錯(cuò)誤信息輸出及郵件發(fā)送相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了PHP實(shí)現(xiàn)的redis主從數(shù)據(jù)庫狀態(tài)檢測功能。分享給大家供大家參考,具體如下:

實(shí)例:

<?php
/**
 * 檢測多個(gè)主從redis數(shù)據(jù)庫是否掛掉
 * 建立從數(shù)據(jù)庫$redis_db的二維數(shù)組,內(nèi)容包含每個(gè)從服務(wù)器的配置數(shù)據(jù)
 */
header("Content-Type: text/html; charset=utf-8");
set_time_limit(0);
$redis_db = array(
  'db1'=>array(
    'hostname' => '127.0.0.1',
    'port' => 6379,
    'password' => '',
  ),
  'db2'=>array(
    'hostname' => '192.168.2.179',
    'port' => 6379,
    'password' => '111111',
  ),
);
$content = '';
foreach ($redis_db as $db_key) {
  $host = $db_key['hostname'];
  $port = $db_key['port'];
  $redis = new Redis();
  //連接本地的 Redis 服務(wù)
  $status= $redis->connect($host, $port);
  if(!$status) {
    $content .= "redis從數(shù)據(jù)庫( $host )無法連接 ! <br/>";
    continue;
  }
  if(!empty($db_key['password'])) {
    $pass = $redis->auth($db_key['password']);
    if(!$pass) {
      $content .= "redis從數(shù)據(jù)庫( $host )密碼錯(cuò)誤 ! <br/>";
      continue;
    }
  }
  try {
    $config = $redis->info();
    if('up' == $config['master_link_status']) {
    } else {
      $content .= "redis從數(shù)據(jù)庫( $host )掛掉了! <br/>";
    }
  }
  catch(RedisException $e)
  {
    $content .= "redis從數(shù)據(jù)庫( $host )報(bào)錯(cuò):" . $e->getMessage()."<br/>";
  }
}
//若報(bào)錯(cuò)信息不為空,發(fā)送報(bào)錯(cuò)郵件
if(!empty($content)) {
  $title = '主從redis數(shù)據(jù)庫狀態(tài)檢測報(bào)錯(cuò) ';
  $content = date("Y-m-d H:i:s",time()) . "<br/>" . $content;
  $sendurl = "http://localhost/api.com/test.php?title=".$title."&content=".$content;
  $result = file_get_contents($sendurl);
  if('ok' != $result) {
    $message = date("Y-m-d H:i:s",time()).' redisSlave.php 主從redis數(shù)據(jù)庫狀態(tài)檢測報(bào)錯(cuò) 郵件發(fā)送失敗!'."\n";
    $content = str_replace("<br/>", "\n", $content);
    $message .= $content;
    error_log($message,3,"error.log");
  }
}

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+redis數(shù)據(jù)庫程序設(shè)計(jì)技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP基本語法入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論