Profiler Output anhängen

Posted in Zend Framework, 20.12.2013 10:12

in der application.ini enablen

(NUR FÜR DEVELOPMENT_ENV natürlich):


[development : production]
...
resources.db.params.profiler = true

In production-Abschnitt evtl. explizit auf false setzen.

Profiler-Template erstellen

in views/scripts-Pfad integrieren, views/scripts/util/profiler.phtml:


<?php 
// get the default db adapter
$db = Zend_Db_Table::getDefaultAdapter();
$profiler = $db->getProfiler();
if($profiler->getEnabled() && $profiler->getTotalNumQueries() > 0) { ?>
<div style='text-align:center'>
<h2>Database Profiling Report</h2>
    <p>Total queries executed: <?php echo $profiler->getTotalNumQueries()?></p>
    <p>Total elapsed time: <?php echo $profiler->getTotalElapsedSecs()?></p>
</div>
<table class='spreadsheet' cellpadding='0' cellspacing='0' style='margin:10px auto'>
 <thead>
  <tr>
   <th>#</th>
   <th>Query</th>
   <th>Time</th>
  </tr>
 </thead>
 <tbody>
<?php foreach ($profiler->getQueryProfiles() as $queryNumber => $query) { ?>
 <tr>
  <td>(<?php echo $queryNumber + 1?>)</td>
  <td><?php echo $query->getQuery();?></td>
  <td><?php echo $query->getElapsedSecs();?></td>
 </tr>
<?php }?>
</tbody>
</table>
<?php }?>


Profilertemplate in Layout einbinden

diese Template in das Pagelayout integieren (layout/layout.phtml?) am besten wohl im Footer):


<?php
$this->addScriptPath(APPLICATION_PATH . '/views/scripts');
echo $this->render('util/profiler.phtml');
?>