endeveit/btp-api

BTP守护进程的API库。

dev-master 2016-04-26 10:27 UTC

This package is not auto-updated.

Last update: 2024-09-14 11:49:00 UTC


README

BTP守护进程的API库

BTP守护进程是由Mamba门户的开发者开发的性能分析守护进程。

这个库是官方旧式的PHP 5.3版本。

使用示例

假设你有一段这样的代码

function getSomethingFromDatabase()
{
    $data   = Database::getConnection()->query('SELECT * FROM `table` WHERE `id` IN (1, 2)');
    $result = array();

    foreach ($data as $row) {
        $result[] = $row[];
    }

    return $result;
}

首先我们应该实例化一个新的Btp\Api\Connection对象

use Btp\Api\Connection;

$btpConnection = new Connection();

现在我们可以使用计数器。

有两种方式使用它们

  • 显式停止计数器。
// 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;
}
  • 在析构函数中停止计数器。
// 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;
}