endeveit / btp-api
API library for BTP daemon.
Installs: 6 280
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=5.3
This package is not auto-updated.
Last update: 2024-12-21 13:07:03 UTC
README
API library for BTP daemon.
BTP daemon is performance analysis daemon from developers of Mamba portal.
This library is PHP 5.3 port of official old-style library.
Example of usage
Let's say you have a code like this:
function getSomethingFromDatabase() { $data = Database::getConnection()->query('SELECT * FROM `table` WHERE `id` IN (1, 2)'); $result = array(); foreach ($data as $row) { $result[] = $row[]; } return $result; }
First we should instantiate new Btp\Api\Connection object:
use Btp\Api\Connection; $btpConnection = new Connection();
Now we can work with counters.
There is two ways to use them:
- The explicit stop of counter.
// Will be measured only time of Database::getConnection()->query() function getSomethingFromDatabase(Connection $btpConnection) { $counter = $btpConnection->getCounter(array( 'srv' => 'db7', 'service' => 'mysql', 'op' => 'select', )); $data = Database::getConnection()->query('SELECT * FROM `table` WHERE `id` IN (1, 2)'); $counter->stop(); $result = array(); foreach ($data as $row) { $result[] = $row[]; } return $result; }
- Counter stop in destructor.
// Will be measured all operations from time of counter initialization till the function // return statement (when the Btp\Api\Counter object's destructor will be called) function getSomethingFromDatabase(Connection $btpConnection) { $counter = $btpConnection->getCounter(array( 'srv' => 'db7', 'service' => 'mysql', 'op' => 'select', )); $data = Database::getConnection()->query('SELECT * FROM `table` WHERE `id` IN (1, 2)'); $result = array(); foreach ($data as $row) { $result[] = $row[]; } return $result; }