Zend_Db_Profiler 不记录数据库连接时间?
遵循 http://framework.zend.com/manual 上的示例代码/en/zend.db.profiler.html 我已经设置了我的 Zend Framework 应用程序的数据库分析。
application.ini:
db.profiler.enabled = true
视图助手:
$totalTime = $profiler->getTotalElapsedSecs();
$queryCount = $profiler->getTotalNumQueries();
$longestTime = 0;
$longestQuery = null;
foreach ($profiler->getQueryProfiles() as $query) {
if ($query->getElapsedSecs() > $longestTime) {
$longestTime = $query->getElapsedSecs();
$longestQuery = $query->getQuery();
}
}
echo 'Executed ' . $queryCount . ' queries in ' . $totalTime . ' seconds' . "\n";
echo 'Average query length: ' . $totalTime / $queryCount . ' seconds' . "\n";
echo 'Queries per second: ' . $queryCount / $totalTime . "\n";
echo 'Longest query length: ' . $longestTime . "\n";
echo "Longest query: \n" . $longestQuery . "\n";
它适用于选择/插入/更新/删除查询。
但我无论如何都找不到让探查器显示启动实际数据库连接所需的时间,尽管文档暗示它确实记录了这一点。
我怀疑 Zend_Db 根本不使用探查器记录与数据库的连接。
有谁知道这是怎么回事?
我正在使用 Oracle 数据库适配器和 ZF 1.10.1
更新:
我了解可以过滤探查器输出,以便它仅显示某些查询类型,例如选择/插入/更新。似乎还有一个仅过滤连接记录的选项:
$profiler->setFilterQueryType(Zend_Db_Profiler::CONNECT);
但是,我的问题是探查器不首先记录连接,因此此过滤器不执行任何操作。
我确实知道这一点,因为如果我打印探查器对象,它包含许多不同查询的数据 - 但没有连接查询的数据:
print_r($profiler);
//output Zend_Db_Profiler Object ( [_queryProfiles:protected] => Array ( [0] => Zend_Db_Profiler_Query Object ( [_query:protected] => select * from table1 [_queryType:protected] => 32 [_startedMicrotime:protected] => 1268104035.3465 [_endedMicrotime:protected] => 1268104035.3855 [_boundParams:protected] => Array ( ) ) [1] => Zend_Db_Profiler_Query Object ( [_query:protected] => select * from table2 [_queryType:protected] => 32 [_startedMicrotime:protected] => 1268104035.3882 [_endedMicrotime:protected] => 1268104035.419 [_boundParams:protected] => Array ( ) ) ) [_enabled:protected] => 1 [_filterElapsedSecs:protected] => [_filterTypes:protected] => )
我做错了什么吗 - 或者连接日志还没有添加到 Zend Framework 中?
Following the sample code on http://framework.zend.com/manual/en/zend.db.profiler.html I have set up db profiling of my Zend Framework app.
application.ini:
db.profiler.enabled = true
View Helper:
$totalTime = $profiler->getTotalElapsedSecs();
$queryCount = $profiler->getTotalNumQueries();
$longestTime = 0;
$longestQuery = null;
foreach ($profiler->getQueryProfiles() as $query) {
if ($query->getElapsedSecs() > $longestTime) {
$longestTime = $query->getElapsedSecs();
$longestQuery = $query->getQuery();
}
}
echo 'Executed ' . $queryCount . ' queries in ' . $totalTime . ' seconds' . "\n";
echo 'Average query length: ' . $totalTime / $queryCount . ' seconds' . "\n";
echo 'Queries per second: ' . $queryCount / $totalTime . "\n";
echo 'Longest query length: ' . $longestTime . "\n";
echo "Longest query: \n" . $longestQuery . "\n";
It works fine for select/insert/update/delete queries.
But I cannot find anyway to get the profiler to show the time taken to initiate the actual db connection, despite the documenation implying that it does log this.
I suspect that Zend_Db simply does not log the connection to the db with the profiler.
Does anyone know what is going on here?
I am using the Oracle database adapter, and ZF 1.10.1
UPDATE:
I understand it is possible to filter the profiler output, such that it will only show certain query types, e.g. select/insert/update. There also appears to be an option to filter just the connection records:
$profiler->setFilterQueryType(Zend_Db_Profiler::CONNECT);
However, my problem is that the profiler is not logging the connections to begin with, so this filter does nothing.
I know this for a fact, because if I print the profiler object, it contains data for many different queries - but no data for the connection queries:
print_r($profiler);
//output Zend_Db_Profiler Object ( [_queryProfiles:protected] => Array ( [0] => Zend_Db_Profiler_Query Object ( [_query:protected] => select * from table1 [_queryType:protected] => 32 [_startedMicrotime:protected] => 1268104035.3465 [_endedMicrotime:protected] => 1268104035.3855 [_boundParams:protected] => Array ( ) ) [1] => Zend_Db_Profiler_Query Object ( [_query:protected] => select * from table2 [_queryType:protected] => 32 [_startedMicrotime:protected] => 1268104035.3882 [_endedMicrotime:protected] => 1268104035.419 [_boundParams:protected] => Array ( ) ) ) [_enabled:protected] => 1 [_filterElapsedSecs:protected] => [_filterTypes:protected] => )
Am I doing something wrong - or has logging of connections just not been added to Zend Framework yet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
探查器将连接和其他操作与一般查询“捆绑”在一起。
您可以通过三种方式专门检查连接:
在设置过程中在探查器上设置过滤器:
<块引用>
然后生成的配置文件将仅包含“连接”操作。
检索查询配置文件时指定查询类型:
<块引用>
在迭代期间直接检查查询对象:
<块引用>
您不会在那里找到详细信息,它只是作为“连接”操作以及所花费的时间进行记录。
The profiler 'bundles' connection and other operations in with the general queries.
There's three ways you might examine the connection specifically:
Set a filter on the profiler during setup:
Then the resultant profiles will only include 'connect' operations.
Specify a query type when you retrieve the Query Profiles:
Examine the query objects directly during the iteration:
You'll not find great detail in there, it's logged just as a 'connect' operation along with the time taken.