$link = mysql_connect ( 'localhost' , 'root' , 'password' ) or die ( '0' ) ; $result = mysql_query ( 'SELECT VERSION();' ) ; if ( ! $result ) die ( '0' ) ; mysql_close ( $link ) ; echo 'OK!' ;
$link = mysql_connect ( 'localhost' , 'root' , 'password' ) or die ( '0' ) ; $result = mysql_query ( 'SELECT VERSION();' ) ; if ( ! $result ) die ( '0' ) ; mysql_close ( $link ) ; echo 'OK!' ;
$link = mysql_connect ( 'localhost' , 'root' , 'password' ) or die ( '0' ) ; $result = mysql_query ( 'SELECT VERSION();' ) ; if ( ! $result ) die ( '0' ) ; mysql_close ( $link ) ; echo 'OK!' ;
$link = mysql_connect ( 'localhost' , 'root' , 'password' ) or die ( '0' ) ; $result = mysql_query ( 'SELECT VERSION();' ) ; if ( ! $result ) die ( '0' ) ; mysql_close ( $link ) ; echo 'OK!' ;
$link = mysql_connect ( 'localhost' , 'root' , 'password' ) or die ( '0' ) ; $result = mysql_query ( 'SELECT VERSION();' ) ; if ( ! $result ) die ( '0' ) ; mysql_close ( $link ) ; echo 'OK!' ;
$link = mysql_connect ( 'localhost' , 'root' , 'password' ) or die ( '0' ) ; $result = mysql_query ( 'SELECT VERSION();' ) ; if ( ! $result ) die ( '0' ) ; mysql_close ( $link ) ; echo 'OK!' ;
- define ( 'MASTER_HOST' , 'xxx.xxx.xxx.xxx' ) ; // IP address of the main server
- define ( 'SLAVE_HOST' , 'xxx.xxx.xxx.xxx' ) ; // IP address of the secondary server
- define ( 'ACCESS_KEY' , 'my_key' ) ; // API Access Key
- define ( 'SECRET_KEY' , 'my_pass' ) ; // Password for access to API
- define ( 'ZONE_ID' , '/ hostedzone / my_zone_id' ) ; // ID of the zone (can be seen after adding the domain to interstate53.com)
- include 'r53.php' ;
- $ route = new Route53 ( ACCESS_KEY , SECRET_KEY ) ;
- $ ns = $ route -> listResourceRecordSets ( ZONE_ID ) ; // Immediately get the values ​​of ns records for the domain
- function test ( ) {
- try {
- $ answer = file_get_contents ( 'http: //' . MASTER_HOST . '/' ) ;
- if ( $ answer == 'OK!' ) // Check the response from the main server
- return true ;
- else
- return false ;
- } catch ( Exception $ e ) {
- return false ;
- }
- }
- function update ( $ arr ) {
- GLOBAL $ route ;
- if ( count ( $ arr ) > 0 )
- {
- $ route -> changeResourceRecordSets ( ZONE_ID , $ arr ) ; // Update ns records
- }
- }
- function changeIP ( $ name , $ ttl , $ from_ip , $ to_ip ) { // The function generates an array in which one record deletes the old one, and the second adds a new one
- return array (
- "
- <Change>
- <Action> DELETE </ Action>
- <ResourceRecordSet>
- <Name> $ name </ name>
- <Type> A </ Type>
- <TTL> $ ttl </ TTL>
- <ResourceRecords>
- <ResourceRecord>
- <Value> $ from_ip </ Value>
- </ ResourceRecord>
- </ ResourceRecords>
- </ ResourceRecordSet>
- </ Change>
- " ,
- "
- <Change>
- <Action> CREATE </ Action>
- <ResourceRecordSet>
- <Name> $ name </ name>
- <Type> A </ Type>
- <TTL> $ ttl </ TTL>
- <ResourceRecords>
- <ResourceRecord>
- <Value> $ to_ip </ Value>
- </ ResourceRecord>
- </ ResourceRecords>
- </ ResourceRecordSet>
- </ Change>
- "
- ) ;
- }
- $ changes = Array ( ) ;
- if ( ! test ( ) ) {
- if ( ! test ( ) ) { // do a test 2 times for reliability
- foreach ( $ ns [ 'ResourceRecordSets' ] as $ record ) {
- if ( $ record [ 'Type' ] == 'A' && $ record [ 'ResourceRecords' ] [ '0' ] == MASTER_HOST ) {
- $ changes = array_merge ( $ changes , changeIP ( $ record [ 'Name' ] , $ record [ 'TTL' ] , MASTER_HOST , SLAVE_HOST ) ) ;
- }
- }
- update ( $ changes ) ;
- exit ( 0 ) ;
- }
- }
- foreach ( $ ns [ 'ResourceRecordSets' ] as $ record ) {
- if ( $ record [ 'Type' ] == 'A' && $ record [ 'ResourceRecords' ] [ '0' ] == SLAVE_HOST ) {
- $ changes = array_merge ( $ changes , changeIP ( $ record [ 'Name' ] , $ record [ 'TTL' ] , SLAVE_HOST , MASTER_HOST ) ) ;
- }
- }
- update ( $ changes ) ;
- exit ( 0 ) ;
Source: https://habr.com/ru/post/122238/
All Articles