# # Use openRemote to create a tunnel to the remote mysql server. # Then try to connect to it every 3 seconds for 15 seconds (I made these numbers # up ... they may need to increase for China ! ) # sub openRemoteSql { $hostname = $_[0] ; $port = $_[1] ; $user = $_[2] ; $pass = $_[3] ; # # Look for a free "port" to use $cnt = 0 ; $tmp = -1 ; while( $tmp == -1 ) { if( $cnt > 10 ) { print "can't find a free port in $_[1] .. $port\n" ; return 0; } $port = $_[1] + $cnt ; #print $port , "\n" ; $tmp = openRemote( $hostname,$port,3306,$user,$pass ) ; $cnt ++; } # # if openRemote returns '0' then the ssh failed, probably can't contact # host or some other shyte # if( $tmp < 1 ) { return $tmp ; } $cnt = 0 ; while( $cnt < 5 ) { $db = DBI->connect("dbi:mysql:database="$remotedb";host=127.0.0.1;port=$port", "$user", "$pass"); if( $db ) { # # Wow .. it all worked ..... # return $db ; } $cnt ++ ; sleep( 3 ) ; } closeRemote($port) ; return 0 ; }