Php AJAX调用的yiisql评测
Yii提供了一个设置,用于配置所有SQL调用以及每个调用的执行时间(CProfileLogRoute)。但它不适用于ajax调用。如何访问此数据 我试图找到打开登录弹出窗口的ajax调用的瓶颈 同样,CProfileLogRoute中显示的执行时间是否包括到SQL server的网络行程(如果有)?我的数据库由Amazon的RDS托管,我想知道这是否是瓶颈所在(在本地似乎很好)。您可以尝试以下面建议的方式进行扩展,并在应用程序的配置中启用它,如下所示:Php AJAX调用的yiisql评测,php,database,amazon-web-services,yii,profiling,Php,Database,Amazon Web Services,Yii,Profiling,Yii提供了一个设置,用于配置所有SQL调用以及每个调用的执行时间(CProfileLogRoute)。但它不适用于ajax调用。如何访问此数据 我试图找到打开登录弹出窗口的ajax调用的瓶颈 同样,CProfileLogRoute中显示的执行时间是否包括到SQL server的网络行程(如果有)?我的数据库由Amazon的RDS托管,我想知道这是否是瓶颈所在(在本地似乎很好)。您可以尝试以下面建议的方式进行扩展,并在应用程序的配置中启用它,如下所示: 'log'=>array(
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'ProfileLogRoute',
'levels' => "profile"
)
)
)
在这种情况下,所有已分析的查询将写入位于protected/runtime
目录中的日志文件中(覆盖processLogs
方法也会实现,同样地,…的摘要报告(不幸的是CProfileWebRoute
源自):
CProfileLogRoute类有一个名为ignoreAjaxInFireBug的属性,通过将其设置为false,该属性默认为“true”您可以获得有关ajax请求的评测信息
我不认为你需要使用firebug来完成这项工作(这有点用词不当)。但是,如果您确实这样做了,只需下载firefox并安装firebug,那么您的问题仍然会得到解决
<?php
class ProfileLogRoute extends CFileLogRoute
{
protected function processLogs($logs)
{
$logFile=$this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
if(@filesize($logFile)>$this->getMaxFileSize()*1024)
$this->rotateFiles();
$fp=@fopen($logFile,'a');
@flock($fp,LOCK_EX);
$profileStack = array();
$profileResults = array();
foreach ($logs as $log)
{
if ($log[1] === CLogger::LEVEL_PROFILE)
{
$message = $log[0];
if (!strncasecmp($message, 'begin:', 6))
{
$log[0] = substr($message,6);
$profileStack[] = $log;
}
else if(!strncasecmp($message, 'end:', 4))
{
$token = substr($message,4);
if(($last = array_pop($profileStack)) !== null && $last[0] === $token)
{
$info = array(
'delta' => $log[3] - $last[3],
'category' => $last[2],
'time' => $last[3]
);
$this->aggregateResult($token, $info, $profileResults);
}
else
{
throw new CException(Yii::t('yii','CProfileLogRoute found a mismatching code block "{token}". Make sure the calls to Yii::beginProfile() and Yii::endProfile() be properly nested.',
array('{token}'=>$token)));
}
}
}
else
{
@fwrite($fp,$this->formatLogMessage($log[0],$log[1],$log[2],$log[3]));
}
}
if (!empty($profileResults))
{
$now = microtime(true);
while(($last = array_pop($profileStack)) !== null)
{
$info = array(
'delta' => $now - $last[3],
'category' => $last[2],
'time' => $last[3]
);
$token = $last[0];
$this->aggregateResult($token, $info, $profileResults);
}
$entries = array_values($profileResults);
$func = create_function('$a,$b','return $a["total"]<$b["total"]?1:0;');
usort($entries, $func);
foreach ($entries as $entry)
{
$message = sprintf("Min: % 11.8f Max: % 11.8f Total: % 11.8f Calls: % 3d %s", $entry['min'], $entry['max'], $entry['total'], $entry['calls'], $entry['token']);
@fwrite($fp, $this->formatLogMessage($message, CLogger::LEVEL_PROFILE, $entry['category'], $entry['time']));
}
}
@flock($fp,LOCK_UN);
@fclose($fp);
}
protected function aggregateResult($token, $info, &$results)
{
if (isset($results[$token]))
{
if ($info['delta'] < $results[$token]['min'])
$results[$token]['min'] = $info['delta'];
else if($info['delta'] > $results[$token]['max'])
$results[$token]['max'] = $info['delta'];
$results[$token]['calls']++;
$results[$token]['total'] += $info['delta'];
return;
}
$results[$token] = array(
'token' => $token,
'calls' => 1,
'min' => $info['delta'],
'max' => $info['delta'],
'total' => $info['delta'],
'category' => $info['category'],
'time' => $info['time']
);
}
}
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CProfileLogRoute',
'ignoreAjaxInFireBug'=>false,
'levels'=>'error, warning, trace, info, profile',
),
),