@@ -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,21 @@ public function getUcHost()
5969 return $ scheme . $ this ->ucHost ;
6070 }
6171
72+ public function appendBackupUcHosts ($ hosts )
73+ {
74+ $ this ->backupUcHosts = array_merge ($ this ->backupUcHosts , $ hosts );
75+ }
76+
77+ public function prependBackupUcHosts ($ hosts )
78+ {
79+ $ this ->backupUcHosts = array_merge ($ hosts , $ this ->backupUcHosts );
80+ }
81+
82+ public function getBackupUcHosts ()
83+ {
84+ return $ this ->backupUcHosts ;
85+ }
86+
6287 public function getUpHost ($ accessKey , $ bucket )
6388 {
6489 $ region = $ this ->getRegion ($ accessKey , $ bucket );
@@ -308,7 +333,13 @@ private function getRegion($accessKey, $bucket)
308333 return $ regionCache ;
309334 }
310335
311- $ region = Zone::queryZone ($ accessKey , $ bucket , $ this ->getUcHost ());
336+ $ region = Zone::queryZone (
337+ $ accessKey ,
338+ $ bucket ,
339+ $ this ->getUcHost (),
340+ $ this ->getBackupUcHosts (),
341+ $ this ->backupUcHostsRetryTimes
342+ );
312343 if (is_array ($ region )) {
313344 list ($ region , $ err ) = $ region ;
314345 if ($ err != null ) {
@@ -332,7 +363,13 @@ private function getRegionV2($accessKey, $bucket)
332363 return array ($ regionCache , null );
333364 }
334365
335- $ region = Zone::queryZone ($ accessKey , $ bucket , $ this ->getUcHost ());
366+ $ region = Zone::queryZone (
367+ $ accessKey ,
368+ $ bucket ,
369+ $ this ->getUcHost (),
370+ $ this ->getBackupUcHosts (),
371+ $ this ->backupUcHostsRetryTimes
372+ );
336373 if (is_array ($ region )) {
337374 list ($ region , $ err ) = $ region ;
338375 return array ($ region , $ err );
0 commit comments