Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
QueryCounter.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Database;
3 
15 class QueryCounter {
16 
20  protected $initial;
21 
25  protected $db;
26 
32  public function __construct(\Elgg\Database $db) {
33  $this->db = $db;
34  $this->initial = $db->getQueryCount();
35  }
36 
42  public function getDelta() {
43  return $this->db->getQueryCount() - $this->initial;
44  }
45 
55  public function setDeltaHeader($key = 'Default') {
56  $delta = $this->getDelta();
57 
58  header("X-ElggQueryDelta-$key: $delta", true);
59  }
60 
70  public function getDeltaScript($key = 'Default') {
71  $delta = $this->getDelta();
72 
73  $msg = json_encode("ElggQueryDelta-$key: $delta");
74  return "<script>console.log($msg)</script>";
75  }
76 }
77 
setDeltaHeader($key= 'Default')
Create header X-ElggQueryDelta-* with the delta.
getDelta()
Get the number of queries performed since the object was constructed.
$key
Definition: summary.php:34
getDeltaScript($key= 'Default')
Get SCRIPT element which sends the delta to console.log.
__construct(\Elgg\Database $db)
Constructor.