Elgg  Version 1.9
QueryCounter.php
Go to the documentation of this file.
1 <?php
2 
15 
19  protected $initial;
20 
24  protected $db;
25 
31  public function __construct(Elgg_Database $db) {
32  $this->db = $db;
33  $this->initial = $db->getQueryCount();
34  }
35 
41  public function getDelta() {
42  return $this->db->getQueryCount() - $this->initial;
43  }
44 
54  public function setDeltaHeader($key = 'Default') {
55  $delta = $this->getDelta();
56 
57  header("X-ElggQueryDelta-$key: $delta", true);
58  }
59 
69  public function getDeltaScript($key = 'Default') {
70  $delta = $this->getDelta();
71 
72  $msg = json_encode("ElggQueryDelta-$key: $delta");
73  return "<script>console.log($msg)</script>";
74  }
75 }
getDelta()
Get the number of queries performed since the object was constructed.
getQueryCount()
Get the number of queries made to the database.
Definition: Database.php:604
$delta
Definition: pagination.php:41
$key
Definition: summary.php:34
setDeltaHeader($key= 'Default')
Create header X-ElggQueryDelta-* with the delta.
__construct(Elgg_Database $db)
Constructor.
clearfix elgg elgg elgg elgg page header
Definition: admin.php:127
getDeltaScript($key= 'Default')
Get SCRIPT element which sends the delta to console.log.