debughub/laravel-client

此包最新版本(0.2.3)没有可用的许可证信息。

Laravel 5.x 的 Debughub 客户端

0.2.3 2017-10-29 16:23 UTC

This package is not auto-updated.

Last update: 2024-09-18 20:59:34 UTC


README

Debughub 通过记录您应用程序的所有请求并在 debughub.com 应用程序中显示它们来帮助您的开发过程。它帮助您更快地找到代码中的问题,并在开发过程中找到性能问题。

安装

此包适用于纯 PHP。对于 Laravel 安装,请访问 debughub 的 Laravel 仓库

  1. 将包添加到 composer.json 中的 require 部分 "debughub/laravel-client": "0.2.*" 用于 Laravel 5.x 和 "debughub/laravel-client": "0.1.*" 用于 Laravel 4.2

  2. 在配置目录中创建新的配置文件,内容如下

<?php
return [
    'api_key' => '', // Your API key
    'project_key' => '', // Your project key
    'git_root' => '', // (Optional) Path to your git root folder. Used to track git branches
    'enabled' => true, // If debughub.com client is enabled.
    'send_query_data' => true, // If you want to send the data insterted into DB queries to debughub.com.
    'blacklist_params' => [ // post and get params, that should never be sent to debughub.com
        'password'
    ]  
];
  1. 在您的 app.php 配置中添加服务提供者 Debughub\Clients\Laravel\DebughubServiceProvider::class

从现在起,debughub 客户端将请求和响应信息发送到 debughub.com

可用的额外方法

您可以使用这些方法添加有关您应用程序的额外信息。您可以使用 debughub 记录查询和日志。所有请求和响应信息将自动发送。

数据库查询

要记录查询,请使用 Debughub::query(string $query, array $data, string $duration, string $connection) 方法。如果您使用 Eloquent 或查询构建器,这将自动完成。如果您使用其他包来处理查询,您需要手动将它们添加到 debughub 报告中。例如,如果您使用一个类来处理所有数据库查询,您可以将此方法添加到调用查询的方法中。或者您也可以在想要记录的查询之后添加它。

$query - 要执行的查询。您可以在查询中添加一个 ? 来替换任何要替换的查询参数。例如 SELECT * FROM Users where id = ?; 并在数据变量中发送用户的 ID。

$data - 应替换代码中 ? 的数据数组。如果您在配置中禁用了 send_query_data,则不会发送此数据。

$duration - 执行查询所需的秒数。

$connection - 数据库连接名称。如果您应用程序使用多个连接,这将很有用。

示例

$db = DB::select("SELECT * FROM USERS"); // some imagined DB class
Debughub::query($db->getQuery(), $db->getData(), $db->getDuration(), 'some connection'); // note - the DB class and its methods are just as a example. the DB class is not part of debughub

或者您可以让 debughub 也计算持续时间,如下所示

$query = "SELECT * FROM USERS";
$debughubQueryIndex = Debughub::startQuery($query, [], 0, 'some connection'); // note - the DB class and its methods are just as a example. the DB class is not part of debughub
$db = DB::select(query); // some imagined DB class
Debughub::endQuery($debughubQueryIndex); // you dont have to get or pass the query index, if it is not passed, the debughub will assume it was the last query you want to update with endQuery() method.

记录

要添加简单的日志,请使用 Debughub::log(string $data, string $type) 方法。日志工作方式与查询类似。您可以使用 log() 方法记录单个操作,例如。

$data - 要记录的数据。可以是任何数据类型,数组和对象将被序列化。

$type (默认为 'info')- 日志名称。这将改变日志在 debughub.com 应用程序中显示的方式。它应该是 infoerrorwarning

Debughub::log('something just happened', 'info');

默认情况下,日志没有持续时间,在 debughub 的时间轴中仅显示为一条小线。如果您想测量某物的持续时间,例如对外部 API 的 API 调用,您可以使用

$debughubLogIndex = Debughub::startLog('something just happened', 'info');
//do some API call or something
Debughub::endLog(debughubLogIndex); // you dont have to get or pass the log index, if it is not passed, the debughub will assume it was the last log you want to update with endLog() method.