@@ -32,6 +32,10 @@ final class Config
3232 private $ regionCache ;
3333 // UC Host
3434 private $ ucHost ;
35+ // backup UC Hosts
36+ private $ backupUcHosts ;
37+ // backup UC Hosts max retry time
38+ public $ backupUcHostsRetryTimes ;
3539
3640 // 构造函数
3741 public function __construct (Region $ z = null )
@@ -41,11 +45,17 @@ public function __construct(Region $z = null)
4145 $ this ->useCdnDomains = false ;
4246 $ this ->regionCache = array ();
4347 $ this ->ucHost = Config::UC_HOST ;
48+ $ this ->backupUcHosts = array (
49+ "kodo-config.qiniuapi.com " ,
50+ "api.qiniu.com "
51+ );
52+ $ this ->backupUcHostsRetryTimes = 2 ;
4453 }
4554
46- public function setUcHost ($ ucHost )
55+ public function setUcHost ($ ucHost, $ backupUcHosts = array () )
4756 {
4857 $ this ->ucHost = $ ucHost ;
58+ $ this ->backupUcHosts = $ backupUcHosts ;
4959 }
5060
5161 public function getUcHost ()
@@ -59,6 +69,18 @@ public function getUcHost()
5969 return $ scheme . $ this ->ucHost ;
6070 }
6171
72+ public function appendBackupUcHosts ($ hosts ) {
73+ $ this ->backupUcHosts = array_merge ($ this ->backupUcHosts , $ hosts );
74+ }
75+
76+ public function prependBackupUcHosts ($ hosts ) {
77+ $ this ->backupUcHosts = array_merge ($ hosts , $ this ->backupUcHosts );
78+ }
79+
80+ public function getBackupUcHosts () {
81+ return $ this ->backupUcHosts ;
82+ }
83+
6284 public function getUpHost ($ accessKey , $ bucket )
6385 {
6486 $ region = $ this ->getRegion ($ accessKey , $ bucket );
@@ -308,7 +330,13 @@ private function getRegion($accessKey, $bucket)
308330 return $ regionCache ;
309331 }
310332
311- $ region = Zone::queryZone ($ accessKey , $ bucket , $ this ->getUcHost ());
333+ $ region = Zone::queryZone (
334+ $ accessKey ,
335+ $ bucket ,
336+ $ this ->getUcHost (),
337+ $ this ->getBackupUcHosts (),
338+ $ this ->backupUcHostsRetryTimes
339+ );
312340 if (is_array ($ region )) {
313341 list ($ region , $ err ) = $ region ;
314342 if ($ err != null ) {
@@ -332,7 +360,13 @@ private function getRegionV2($accessKey, $bucket)
332360 return array ($ regionCache , null );
333361 }
334362
335- $ region = Zone::queryZone ($ accessKey , $ bucket , $ this ->getUcHost ());
363+ $ region = Zone::queryZone (
364+ $ accessKey ,
365+ $ bucket ,
366+ $ this ->getUcHost (),
367+ $ this ->getBackupUcHosts (),
368+ $ this ->backupUcHostsRetryTimes
369+ );
336370 if (is_array ($ region )) {
337371 list ($ region , $ err ) = $ region ;
338372 return array ($ region , $ err );
0 commit comments