Advertisement
kotvalera83

Tracking slow SQL queries in Codeigniter

May 27th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. // index.php
  2. $ci = & get_instance();
  3. $handle = fopen('slow_query_1.log', "a+");
  4. $handle_slow = fopen('slow_query_10.log', "a+");
  5. foreach($ci->db->queries as $key =>$query)
  6. {
  7.     $time = number_format($ci->db->query_times[$key], 4);
  8.     if ($time < 1)
  9.         continue;
  10.     if ($time < 10)
  11.     {
  12.         fwrite($handle, date('j.m.Y G:i:s').' : '.$time."\r\n");
  13.         fwrite($handle, $query."\r\n\r\n-----------------------------\r\n");
  14.     }
  15.     else
  16.     {
  17.         fwrite($handle_slow, date('j.m.Y G:i:s').' : '.$time."\r\n");
  18.         fwrite($handle_slow, $query."\r\n\r\n-----------------------------\r\n");
  19.     }
  20. }
  21. fclose($handle);
  22. fclose($handle_slow);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement