Example of the redis master-slave database status detection function implemented by PHP, redis master-slave

Source: Internet
Author: User

Example of the redis master-slave database status detection function implemented by PHP, redis master-slave

This example describes the redis master-slave database status detection function implemented by PHP. We will share this with you for your reference. The details are as follows:

Instance:

<? Php/*** check whether multiple master-slave redis databases are down * create a two-dimensional array of slave database $ redis_db, the Content contains configuration data for each slave server */header ("Content-Type: text/html; charset = UTF-8"); set_time_limit (0 ); $ redis_db = array ('db1' => array ('hostname' => '2017. 0.0.1 ', 'Port' => 6379, 'Password' => '',), 'db2' => array ('hostname' => '2017. 168.2.179 ', 'Port' => 6379, 'Password' => '000000',),); $ content = ''; foreach ($ redis_db as $ db_key) {$ host = $ db_key ['hostname']; $ po Rt = $ db_key ['Port']; $ redis = new Redis (); // connect to the local Redis service $ status = $ redis-> connect ($ host, $ port); if (! $ Status) {$ content. = "redis cannot be connected from the database ($ host! <Br/> "; continue;} if (! Empty ($ db_key ['Password']) {$ pass = $ redis-> auth ($ db_key ['Password']); if (! $ Pass) {$ content. = "redis slave database ($ host) Password error! <Br/> "; continue; }}try {$ config = $ redis-> info (); if ('up' = $ config ['master _ link_status ']) {} else {$ content. = "redis crashed from the database ($ host! <Br/> ";}} catch (RedisException $ e) {$ content. = "redis slave database ($ host) error :". $ e-> getMessage (). "<br/>" ;}}// if the error message is not blank, send an error email if (! Empty ($ content) {$ title = 'error in Master/Slave redis database status detection '; $ 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 Master/Slave redis database status detection error email sending failed! '. "\ N"; $ content = str_replace ("<br/>", "\ n", $ content); $ message. = $ content; error_log ($ message, 3, "error. log ");}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.