雪域 / phalcon-debugbar
将PHP调试条与Phalcon集成。
Requires
- php: >=5.5.0
- filp/whoops: ^2
- maximebf/debugbar: ^1
- dev-master
- 3.0.x-dev
- 2.0.x-dev
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.30
- v1.1.29
- v1.1.28
- v1.1.27
- v1.1.26
- v1.1.25
- v1.1.24
- v1.1.23
- v1.1.22
- v1.1.21
- v1.1.20
- v1.1.19
- v1.1.18
- v1.1.16
- v1.1.15
- v1.1.14
- v1.1.13
- v1.1.12
- v1.1.11
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1
- 1.0.x-dev
- v1.0.2
- v1.0.1
- v1.0
This package is not auto-updated.
Last update: 2024-09-19 02:13:59 UTC
README
Phalcon调试条
功能
- 普通请求捕获
- Ajax请求捕获
- 重定向请求链捕获
- 支持简单的App、多模块App和微服务App
- 收集的数据持久化:保存到本地文件或MongoDB,或ElasticSearch
- 使用sessionid存储数据,更适合团队开发。
- 您可以关闭注入调试条,并在新的浏览器标签页中访问
/_debugbar/open
来查看数据(它也可以被禁用)。 - Whoops集成,调试条与它配合良好。
- 支持Phalcon 1.3.x、2.x、3.x,PHP5.5~7.1
支持收集器
- MessagesCollector:收集自定义消息,支持标量、数组和对象
- TimeDataCollector:收集自定义时间度量。
- ExceptionsCollector:向调试条添加异常对象。
- MemoryCollector:收集内存使用情况。
- QueryCollector:捕获每个SQL语句,测量每个SQL的耗时,显示每个SELECT语句的EXPLAIN结果
- 从
db
服务收集信息。仅适用于Phalcon ORM。
- 从
- DoctrineCollector:捕获Doctrine中的每个SQL语句,测量每个SQL的耗时。
- 从
entityManager
服务收集信息。仅适用于Doctrine ORM。
- 从
- RouteCollector:显示当前请求的路由信息。
- 从
router
服务收集信息。
- 从
- ViewCollector:显示所有已渲染的模板,测量每个模板的耗时,显示所有模板变量。
- 从
view
服务收集信息。
- 从
- PhalconRequestCollector:显示请求头、Cookies、服务器变量、响应头、查询、POST数据、原始体
- 从
request
服务收集信息。
- 从
- ConfigCollector:显示config服务中的数据。
- 从
config
服务收集信息。
- 从
- SessionCollectior:显示会话数据
- 从
session
服务收集信息。
- 从
- SwiftMailCollector:邮件发送器信息
- 从
mail
服务收集信息。
- 从
- LogsCollectors:显示当前请求的日志。支持
Phalcon\Logger
和Monolog
- 从
log
服务收集信息。
- 从
- CacheCollectors:显示缓存摘要(保存、获取、增、减、失败),以及每个缓存操作的详细信息。
- 从
cache
服务收集信息。
- 从
快速开始
composer
-
安装
php composer.phar require --dev snowair/phalcon-debugbar
-
更新
php composer.phar update snowair/phalcon-debugbar
修改index.php
-
将您的App实例设置为DI
$application = new Phalcon\Mvc\Application( $di ); // Important: mustn't ignore $di param . The Same Micro APP: new Phalcon\Mvc\Micro($di); $di['app'] = $application; // Important
-
在处理应用程序之前,注册和启动调试条提供者。
(new Snowair\Debugbar\ServiceProvider())->start(); // after start the debugbar, you can do noting but handle your app right now. echo $application->handle()->getContent();
-
可选使用Whoops,修改index.php,在调试条服务
start()
方法下方添加以下代码。(new \Snowair\Debugbar\Whoops\WhoopsServiceProvider($di));
修改ACL代码
以下是一个INVO的示例
public function beforeDispatch(Event $event, Dispatcher $dispatcher)
{
$auth = $this->session->get('auth');
if (!$auth){
$role = 'Guests';
} else {
$role = 'Users';
}
$controller = $dispatcher->getControllerName();
$action = $dispatcher->getActionName();
/* Debugbar start */
$ns = $dispatcher->getNamespaceName();
if ($ns=='Snowair\Debugbar\Controllers') {
return true;
}
/* Debugbar end */
$acl = $this->getAcl();
$allowed = $acl->isAllowed($role, $controller, $action);
if ($allowed != Acl::ALLOW) {
$dispatcher->forward(array(
'controller' => 'errors',
'action' => 'show401'
));
$this->session->destroy();
return false;
}
}
数据持久化
对于file
驱动程序,默认的存储调试条数据的目录是Runtime/phalcon
。如果不存在,它将自动创建。您可以通过重新配置来更改它。
对于 mongodb 驱动程序,您必须安装 mongodb 扩展并安装 phplib:composer require mongodb/mongodb
对于 elastic 驱动程序,您必须安装 phplib:composer require elasticsearch/elasticsearch:some-version
关于 baseUri
请注意您项目的 baseUri 配置,您必须为您的 uri 服务设置正确的 baseUri。
如果您使用的是 apache,您应该启用 Rewrite 模块,并在 baseUri 目录下创建一个 .htaccess
文件。
如果您使用的是 nginx,您应该启用 Rewrite 模块,并像这样编辑服务器配置中的 location 块
location @rewrite {
# replace 'baseuri' to your real baseuri
rewrite ^/baseuri/(.*)$ /baseuri/index.php?_url=/$1;
}
更多
使用您的配置
将 config/debugbar.php
复制到您的配置目录,并根据需要更改任何设置。然后通过以下方式使用您的 debugbar 配置文件:
(new Snowair\Debugbar\ServiceProvider('your-debugbar-config-file-path'))->start();
向 debugbar 发送自定义消息
\PhalconDebug::startMeasure('start-1','how long'); // startMeasure($internal_sign_use_to_stop_measure, $label) \PhalconDebug::addMeasurePoint('start'); // measure the spent time from latest measurepoint to now. \PhalconDebug::addMessage('this is a message', 'label'); // add a message using a custom label. \PhalconDebug::info($var1,$var2, $var3, ...); // add many messages once a time. See PSR-3 for other methods name.(debug,notice,warning,error,...) \PhalconDebug::addMessageIfTrue('1 == "1"', 1=='1','custom_label'); // add message only when the second parameter is true \PhalconDebug::addMessageIfTrue('will not show', 1=='0'); \PhalconDebug::addMessageIfFalse('1 != "0" ', 1=='0'); // add message only when the second parameter is false \PhalconDebug::addMessageIfNull('condition is null', Null ); // add message only when the second parameter is NULL \PhalconDebug::addMessageIfEmpty('condition is emtpy', $condition ); // add message only when the second parameter is empty \PhalconDebug::addMessageIfNotEmpty('condition is not emtpy', $condition=[1] ); // add message only when the second parameter is not empty \PhalconDebug::addException(new \Exception('oh , error')); \PhalconDebug::addMeasurePoint('stop'); \PhalconDebug::stopMeasure('start-1'); // stopMeasure($internal_sign_use_to_stop_measure)
Voltp 函数
addMessage
addMessageIfTrue
addMessageIfFalse
addMessageIfNull
addMessageIfEmpty
addMessageIfNotEmpty
addException
addMeasurePoint
startMeasure
stopMeasure
debug/info/notice/warning/error/emergency/critical
示例
{{ debug( var1, var2 )}}
{{ info( var1, var2 )}}
{{ addMessageIfTrue('$var === true', var ) }}
多模块
通常,如果您遵循以下规则,您不需要修改其他任何文件
- 所有缓存服务名称都包含
cache
。 - 所有数据库服务名称以
db
开头或以db
结尾。 - 访问
/_debugbar/open?m={modulename}
以打开独立的 debugbar 页面。
如果您的服务名称不符合这些规则,您需要将其附加到 debugbar
// service.php $di->set('read-db-test',function(...)); // db service $di->set('redis',function(...)); // cache service if ( $di->has('debugbar') ) { $debugbar = $di['debugbar']; $debugbar->attachDb('read-db-test'); $debugbar->attachCache('redis'); }
故障排除
-
我强烈建议您为您的项目分配一个 主机域名,并将
uri
服务的 baseUri 设置为/
。 -
对于 ajax/json 请求,调试数据仅以 json 文件的形式存储在持久目录中。您可以通过 Openhandler(右侧的打开图标)将其加载到 debugbar 中。
-
如果 debugbar 无法正常工作,最可能的原因是一个或多个收集器在运行时触发了错误。您可以修改 debugbar 配置文件,逐个关闭收集器,重试直到找到导致问题的收集器。
-
对于任何问题,您可以在 Github 上提交一个 Issue。