页面 500。
调试模式下打开 发现 Requested API Server list from CDN failed报错
1.
如果你是 企培版本号低于5.0.0/ 教培版本号低于8.3.32
问题原因
由于 api-common.b0.upaiyun.com
域名为云平台获取API地址的备用域名地址,而该域名已经停止解析,所以需要人工指定 host
。
解决方案
在网校服务器上的的 /etc/hosts
文件中添加一行:
|
2.如果你是内网下使用的且 ‘项目目录/app/data/api_server.json’ 中空白
问题原因 项目目录/app/data/api_server.json 中空白导致借口走不通
解决方案
添加内容 api_server.json中添加
{"root":"http:\/\/api.edusoho.net","leafs":[{"url":"http:\/\/leafapi1.edusoho.net","used_count":0},{"url":"http:\/\/leafapi2.edusoho.net","used_count":0}],"current_leaf":"http:\/\/leafapi2.edusoho.net","failed_count":0,"failed_expired":0,"next_refresh_time":1652733014}
或者一步到位修改代码
修改src/Biz/CloudPlatform/Client/FailoverCloudAPI.php 文件中的 getServerList方法
public function getServerList($nextRefreshTime = 0)
{
$prevApiUrl = $this->apiUrl;
$this->setApiUrl($this->rootApiUrl);
$servers = parent::_request('GET', '/server_list', array(), array());
$servers = '{"root":"http:\/\/api.edusoho.net","leafs":[{"url":"http:\/\/leafapi1.edusoho.net","used_count":0},{"url":"http:\/\/leafapi2.edusoho.net","used_count":0}],"current_leaf":"http:\/\/leafapi2.edusoho.net","failed_count":0,"failed_expired":0,"next_refresh_time":1652733014}';
$servers = json_decode($servers, true);
$this->setApiUrl($prevApiUrl);
if (empty($servers) || empty($servers['root']) || empty($servers['current_leaf']) || empty($servers['leafs'])) {
$servers = $this->getServerListFromCdn();
if (empty($servers) || empty($servers['root']) || empty($servers['leafs'])) {
throw new \RuntimeException('Requested API Server list from CDN failed.');
}
}
if (empty($servers['current_leaf'])) {
$servers['current_leaf'] = $servers['leafs'][array_rand($servers['leafs'])]['url'];
}
foreach ($servers['leafs'] as &$leaf) {
$leaf['used_count'] = 0;
unset($leaf);
}
$servers['failed_count'] = 0;
$servers['failed_expired'] = 0;
if (empty($nextRefreshTime)) {
//确保每天的凌晨0~5点之间的时间内更新
$hour = rand(0, 5);
$minute = rand(0, 59);
$second = rand(0, 59);
$nextRefreshTime = strtotime(date('Y-m-d 0:0:0', strtotime('+1 day'))) + $hour * 3600 + $minute * 60 + $second;
}
$servers['next_refresh_time'] = $nextRefreshTime;
return $servers;
}