Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Some little updates.

  • Loading branch information...
commit b5f139b3962a4669db58c6b3cec6493666ab203e 1 parent 673f3c1
Marc Ghorayeb authored
Showing with 55 additions and 16 deletions.
  1. +6 −2 README
  2. +49 −14 config/bootstrap.php
View
8 README
@@ -1,5 +1,9 @@
+This is a plug-in for the Lithium php framework.
+
+It will append to your pages the execution time needed to display that page and the queries that were executed on your database.
+
TODO:
-- List of queries
+- List of queries (SQL, Mongo)
- Display execution speed
- Display header
-- Display template vars
+- Display template vars
View
63 config/bootstrap.php
@@ -4,30 +4,65 @@
use lithium\analysis\Logger;
use lithium\core\Environment;
+global $APP_START_TIME, $SQL;
+
+$APP_START_TIME = microtime(true);
+$SQL = array();
+
+// Configure the Logger class to use the File adapter by default
+Logger::config(array(
+ 'default' => array('adapter' => 'File')
+));
+
// Force development environment
Environment::set('development');
// Force PHP error display
ini_set("display_errors", 1);
-$APP_START_TIME = microtime();
+register_shutdown_function('li3_debug_exit');
-Dispatcher::applyFilter('run', function($self, $params, $chain) use ($APP_START_TIME){
- $r = $chain->next($self,$params,$chain);
+function li3_debug_exit() {
+ global $SQL, $APP_START_TIME;
+ ?>
+ <hr/>
+ <div>
+ <span>Temps d'exécution: <?= round(microtime(true) - $APP_START_TIME, 4) ?> secondes.</span>
+ <ul>
+ <?php foreach ($SQL as $query) : ?>
+ <li><?= $query ?></li>
+ <?php endforeach; ?>
+ </ul>
+ </div>
+ <?php
+}
- $APP_END_TIME = microtime();
- $times = array_map(
- function($a){
- $time = explode(' ', $a);
- return $time[1] + $time[0];
- },
- array($APP_START_TIME, $APP_END_TIME)
- );
+function addSqlLine($query) {
+ global $SQL;
+ $SQL[] = $query;
+}
- $t = $times[1]-$times[0];
+// Thanks to li3_profiler for this bit of code
+// SQL query logging
+use \lithium\util\collection\Filters;
+use \lithium\data\Connections;
- Logger::debug('*** PAGE EXECUTION TIME:'.$t);
+// Attach to the `Connections` adapters after dispatch.
+Filters::apply('\lithium\action\Dispatcher', '_callable', function($self, $params, $chain) {
+ /**
+ * Loop over all defined `Connections` adapters and tack in our
+ * filter on the `_execute` method.
+ */
+ foreach (Connections::get() as $connection) {
+ $connection = Connections::get($connection);
+ $connection->applyFilter('_execute', function($self, $params, $chain) {
+ addSqlLine($params['sql']);
+ return $chain->next($self, $params, $chain);
+ });
+ }
- return $r;
+ // Return the controller.
+ return $chain->next($self, $params, $chain);
});
+
?>
Please sign in to comment.
Something went wrong with that request. Please try again.