In Yii 2.0, the browser finds unresponsive, and then repeats the investigation and analysis of the request
1. There is no response in Yii 2.0, which leads to repeated requests in the browser 2 times. No response for the first time, and an error for the second time (procedure forbidding duplicate requests). as shown in Figure 1
2. View the details of the first request, in the header – general, no response status code. as shown in Figure 2
3. View the details of the first request, in the response, the response data cannot be loaded. as shown in Figure 3
4. Check Log Messages, in E:\wwwroot\channel-pub-api\common\services\weiboWeiBoConnectWebAppAccessTokenService.php:92 The execution is stopped and the execution should be continued. as shown in Figure 4
5. Check the code, line 92: $weiboWeiBoConnectWebAppUserAccessToken->Save()
public function saveModel($data)
{
/* 基于微博的微连接的网页应用的用户ID查找状态为启用的单个资源 */
$weiboWeiboConnectWebAppUserAccessToken = WeiboWeiboConnectWebAppUserAccessToken::find()->where(['weibo_weibo_connect_web_app_user_id' => $data['weiboWeiboConnectWebAppUserId']])->isDeletedNo()->enabled()->one();
if (!isset($weiboWeiboConnectWebAppUserAccessToken)) {
$weiboWeiboConnectWebAppUserAccessToken = new WeiboWeiboConnectWebAppUserAccessToken();
}
// 设置访问令牌的有效截止时间
$time = time();
$accessTokenExpireAt = $time + $data['expires_in'] + Yii::$app->params['weiboAuth']['weiboConnectWebApp']['authPeriod'] - Yii::$app->params['refreshToken']['timeOut'];
$weiboWeiboConnectWebAppUserAccessToken->attributes = [
'weibo_weibo_connect_web_app_id' => $data['weiboWeiboConnectWebAppId'],
'channel_app_source_id' => $data['channelAppSourceId'],
'channel_app_source_uuid' => $data['channelAppSourceUuid'],
'weibo_weibo_connect_web_app_user_id' => $data['weiboWeiboConnectWebAppUserId'],
'weibo_weibo_connect_web_app_user_uuid' => $data['weiboWeiboConnectWebAppUserUuid'],
'grant_type' => $data['grantType'],
'access_token' => $data['access_token'],
'expires_in' => $data['expires_in'],
'expires_at' => $accessTokenExpireAt,
'scope' => isset($data['scope']) ? $data['scope'] : '',
'user_id' => $data['uid'],
'status' => WeiboWeiboConnectWebAppUserAccessToken::STATUS_ENABLED,
];
if ($weiboWeiboConnectWebAppUserAccessToken->save()) {
return ['status' => true, 'data' => ['channel_app_source_uuid' => $data['channelAppSourceUuid']]];
} elseif ($weiboWeiboConnectWebAppUserAccessToken->hasErrors()) {
$firstError = '';
foreach ($weiboWeiboConnectWebAppUserAccessToken->getFirstErrors() as $message) {
$firstError = $message;
break;
}
return ['status' => false, 'code' => 214010, 'message' => Yii::t('error', Yii::t('error', Yii::t('error', '214010'), ['first_error' => $firstError]))];
} elseif (!$weiboWeiboConnectWebAppUserAccessToken->hasErrors()) {
throw new ServerErrorHttpException('Failed to insert/update the object (microblogging micro-connected web application user\'s access token) for unknown reason.');
}
}
6. Print the object before line 92: $weiboWeiBoConnectWebAppUserAccessToken. The print result is as follows. And the first request to respond to 200. as shown in Figure 5
common\logics\WeiboWeiboConnectWebAppUserAccessToken Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[weibo_weibo_connect_web_app_id] => 1
[channel_app_source_id] => 39
[channel_app_source_uuid] => c28915a6a8cb11ebba6254ee75d2ebc1
[weibo_weibo_connect_web_app_user_id] => 6
[weibo_weibo_connect_web_app_user_uuid] => c28a3efea8cb11ebb69354ee75d2ebc1
[grant_type] => authorization_code
[access_token] => 2.00bAKoqCV9i7fEee243e798c0zzui2
[expires_in] => 2626935
[expires_at] => 1622394001
[scope] =>
[user_id] => 2612590013
[status] => 1
)
)
7. Edit the code, No. 92 Line: $weiboWeiBoConnectWebAppUserAccessToken->Save(false ), and do not verify before storing the records (the data is trusted), so as to avoid the long verification time, which leads to the situation that the response time is too long, and the browser repeats the request. Note: Previously, this model was the Redis AR model, which was later adjusted to the MySQL AR model. The length of the viewer in the browser is: 2.57 seconds. As shown in Figure 6, Figure 7
public function saveModel($data)
{
/* 基于微博的微连接的网页应用的用户ID查找状态为启用的单个资源 */
$weiboWeiboConnectWebAppUserAccessToken = WeiboWeiboConnectWebAppUserAccessToken::find()->where(['weibo_weibo_connect_web_app_user_id' => $data['weiboWeiboConnectWebAppUserId']])->isDeletedNo()->enabled()->one();
if (!isset($weiboWeiboConnectWebAppUserAccessToken)) {
$weiboWeiboConnectWebAppUserAccessToken = new WeiboWeiboConnectWebAppUserAccessToken();
}
// 设置访问令牌的有效截止时间
$time = time();
$accessTokenExpireAt = $time + $data['expires_in'] + Yii::$app->params['weiboAuth']['weiboConnectWebApp']['authPeriod'] - Yii::$app->params['refreshToken']['timeOut'];
$weiboWeiboConnectWebAppUserAccessToken->attributes = [
'weibo_weibo_connect_web_app_id' => $data['weiboWeiboConnectWebAppId'],
'channel_app_source_id' => $data['channelAppSourceId'],
'channel_app_source_uuid' => $data['channelAppSourceUuid'],
'weibo_weibo_connect_web_app_user_id' => $data['weiboWeiboConnectWebAppUserId'],
'weibo_weibo_connect_web_app_user_uuid' => $data['weiboWeiboConnectWebAppUserUuid'],
'grant_type' => $data['grantType'],
'access_token' => $data['access_token'],
'expires_in' => $data['expires_in'],
'expires_at' => $accessTokenExpireAt,
'scope' => isset($data['scope']) ? $data['scope'] : '',
'user_id' => $data['uid'],
'status' => WeiboWeiboConnectWebAppUserAccessToken::STATUS_ENABLED,
];
if ($weiboWeiboConnectWebAppUserAccessToken->save(false)) {
return ['status' => true, 'data' => ['channel_app_source_uuid' => $data['channelAppSourceUuid']]];
} elseif ($weiboWeiboConnectWebAppUserAccessToken->hasErrors()) {
$firstError = '';
foreach ($weiboWeiboConnectWebAppUserAccessToken->getFirstErrors() as $message) {
$firstError = $message;
break;
}
return ['status' => false, 'code' => 214010, 'message' => Yii::t('error', Yii::t('error', Yii::t('error', '214010'), ['first_error' => $firstError]))];
} elseif (!$weiboWeiboConnectWebAppUserAccessToken->hasErrors()) {
throw new ServerErrorHttpException('Failed to insert/update the object (microblogging micro-connected web application user\'s access token) for unknown reason.');
}
}
8. Check the response time of the first request when the repeat request is repeated twice, all of which are more than 2500 ms. as shown in Figure 8
9. Restore the code, line 92: $weiboWeiBoConnectWebAppUserAccessToken->Save(). When the environment is set to: Production, the response time is not too long. The length of the viewer in the browser is: 1.56 seconds. From this, it is concluded that the validation of the response will certainly affect the response time, but it is basically caused by the development of the environment. as shown in Figure 9








