33 lines
1.1 KiB
Plaintext
33 lines
1.1 KiB
Plaintext
+++ Introduction
|
|
{{Doctrine_Connection_Profiler}} is an eventlistener for {{Doctrine_Connection}}. It provides flexible query profiling. Besides the SQL strings the query profiles include elapsed time to run the queries. This allows inspection of the queries that have been performed without the need for adding extra debugging code to model classes.
|
|
|
|
{{Doctrine_Connection_Profiler}} can be enabled by adding it as an eventlistener for {{Doctrine_Connection}}.
|
|
|
|
<code type="php">
|
|
$conn = Doctrine_Manager::connection($dsn);
|
|
|
|
$profiler = new Doctrine_Connection_Profiler();
|
|
|
|
$conn->setListener($profiler);
|
|
</code>
|
|
+++ Basic usage
|
|
|
|
Perhaps some of your pages is loading slowly. The following shows how to build a complete profiler report from the connection:
|
|
|
|
<code type="php">
|
|
$time = 0;
|
|
foreach ($profiler as $event) {
|
|
$time += $event->getElapsedSecs();
|
|
echo $event->getName() . " " . sprintf("%f", $event->getElapsedSecs()) . "<br>\n";
|
|
echo $event->getQuery() . "<br>\n";
|
|
$params = $event->getParams();
|
|
if( ! empty($params)) {
|
|
var_dump($params);
|
|
}
|
|
}
|
|
echo "Total time: " . $time . "<br>\n";
|
|
</code>
|
|
|
|
+++ Advanced usage
|
|
|