Class Phalcon\Db\Profiler

Instances of Phalcon\Db can generate execution profiles on SQL statements sent to the relational database. Profiled information includes execution time in miliseconds. This helps you to identify bottlenecks in your applications.

  1. <?php
  2. $profiler = new \Phalcon\Db\Profiler();
  3. //Set the connection profiler
  4. $connection->setProfiler($profiler);
  5. $sql = "SELECT buyer_name, quantity, product_name
  6. FROM buyers LEFT JOIN products ON
  7. buyers.pid=products.id";
  8. //Execute a SQL statement
  9. $connection->query($sql);
  10. //Get the last profile in the profiler
  11. $profile = $profiler->getLastProfile();
  12. echo "SQL Statement: ", $profile->getSQLStatement(), "\n";
  13. echo "Start Time: ", $profile->getInitialTime(), "\n";
  14. echo "Final Time: ", $profile->getFinalTime(), "\n";
  15. echo "Total Elapsed Time: ", $profile->getTotalElapsedSeconds(), "\n";

Methods

public Phalcon\Db\Profiler startProfile (unknown $sqlStatement, [unknown $sqlVariables], [unknown $sqlBindTypes])

Starts the profile of a SQL sentence

public Phalcon\Db\Profiler stopProfile ()

Stops the active profile

public integer getNumberTotalStatements ()

Returns the total number of SQL statements processed

public double getTotalElapsedSeconds ()

Returns the total time in seconds spent by the profiles

public Phalcon\Db\Profiler\Item [] getProfiles ()

Returns all the processed profiles

public Phalcon\Db\Profiler reset ()

Resets the profiler, cleaning up all the profiles

public Phalcon\Db\Profiler\Item getLastProfile ()

Returns the last profile executed in the profiler