nayti/phalcon-debugbar
Composer 安装命令:
composer require nayti/phalcon-debugbar
包简介
Integrates PHP Debug Bar with Phalcon. is fork snowair/phalcon-debugbar
README 文档
README
Phalcon Debugbar
Integrates PHP Debug Bar with Phalcon Framework.
Features
- Normal request capturing
- Ajax request capturing
- Redirect request chain capturing
- Simple App, Multi module App and Micro App support
- Data collected persistent : save to Local File or MongoDB, or ElasticSearch
- Data storaged by sessionid, it's more firendly for team development.
- You can close inject debugbar, and on a new browser tab, visit
/_debugbar/opento see data(and it alse can be disabled). - Whoops Integration, and debugbar works well with it.
- Support palcon 1.3.x,2.x,3.x, PHP5.5~7.1
Support Collectors
- MessagesCollector: Collect custom message, support scalar, array and object
- TimeDataCollector: Collect custom time measure.
- ExceptionsCollector: Add a exception object to debugbar.
- MemoryCollector: Collect memory usage
- QueryCollector: Capture each SQL statement, measure spent time of each SQL, show EXPLAIN result of each SELECT statement
- collect information from the
dbservice. Only for Phalcon ORM.
- collect information from the
- DoctrineCollector: Capture each SQL statement in Doctrine, measure spent time of each SQL.
- collect information from the
entityManagerservice. Only for Doctrine ORM.
- collect information from the
- RouteCollector: Show Route info of current request.
- collect information from the
routerservice.
- collect information from the
- ViewCollector: Show all the rendered templates, measure spent time of each template, show all the templates variables.
- collect information from the
viewservice.
- collect information from the
- PhalconRequestCollector: Show request headers, cookies, server variables, response headers, querys, post data,raw body
- collect information from the
requestservice.
- collect information from the
- ConfigCollector: Show the data in the config service.
- collect information from the
configservice.
- collect information from the
- SessionCollectior: Show session data
- collect information from the
sessionservice.
- collect information from the
- SwiftMailCollector: mailer info
- collect information from the
mailservice.
- collect information from the
- LogsCollectors: Show logs of current request. Support
Phalcon\Loggerand Monolog- collect information from the
logservice.
- collect information from the
- CacheCollectors: Show caches summary (saved,gets,incs,decs,failds), and each cache operation detail.
- collect information from the
cacheservice.
- collect information from the
Quick start
composer
-
install
php composer.phar require --dev snowair/phalcon-debugbar -
update
php composer.phar update snowair/phalcon-debugbar
Modify index.php
-
Set your App Instance to 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
-
Before handle app, register and boot debugbar provider.
(new Snowair\Debugbar\ServiceProvider())->start(); // after start the debugbar, you can do noting but handle your app right now. echo $application->handle()->getContent();
-
optional to use Whoops, modify the index.php, add follow codes bellow the debugbar service
start()method.(new \Snowair\Debugbar\Whoops\WhoopsServiceProvider($di));
Modify The ACL Code
Here is a example for 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;
}
}
Data Persistent
For file driver, the default directory for store debugbar data is Runtime/phalcon. If it doesn't exist, it will be created automatically. You can change it by reconfig.
For mongodb driver, You must install the mongodb extension and install the phplib : composer require mongodb/mongodb
For elastic driver, You must install the phplib : composer require elasticsearch/elasticsearch:some-version
About baseUri
Be aware of the baseUri configuration of your project, you must set a currect baseUri for your uri service.
If you are using apache, you should enable the Rewrite mod and have a .htaccess file under the baseUri directory.
If you are using nginx, you should enable the Rewrite mod and edit the location block of the server configuration like this:
location @rewrite {
# replace 'baseuri' to your real baseuri
rewrite ^/baseuri/(.*)$ /baseuri/index.php?_url=/$1;
}
More
Use your config
Copy config/debugbar.php to your config directory, and change any settings you want. Then use your debugbar config file by:
(new Snowair\Debugbar\ServiceProvider('your-debugbar-config-file-path'))->start();
Send custom messages to 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)
Volt Functions:
addMessage
addMessageIfTrue
addMessageIfFalse
addMessageIfNull
addMessageIfEmpty
addMessageIfNotEmpty
addException
addMeasurePoint
startMeasure
stopMeasure
debug/info/notice/warning/error/emergency/critical
Examples
{{ debug( var1, var2 )}}
{{ info( var1, var2 )}}
{{ addMessageIfTrue('$var === true', var ) }}
Multi Modules
Usually, You needn't modify any other files, if you follow rules bellow:
- All the services for cache has a name contain
cache. - All the services for db has a name start with
dbor end withdb. - Visit
/_debugbar/open?m={modulename}to open a independent debugbar page.
If your service name is't match these rules, you need attach it to 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'); }
Troubleshooting
-
I strongly suggest you to assign a host domain to your project, and set the baseUri of
uriservice to/. -
For ajax/json request, the debug data only stored in the persistent directory as a json file. You can Load it to the debugbar form Openhandler(Open icon on the right).
-
If the debugbar does not work, the most likely reason is that one or more collectors triggered a error in the runtime. You can modify the debugbar config file, close collector one by one, retry it until found the collector cause problem.
-
For any problems, you can open an Issue on Github.
Snapshots
nayti/phalcon-debugbar 适用场景与选型建议
nayti/phalcon-debugbar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「debug」 「profiler」 「debugbar」 「phalcon」 「webprofiler」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nayti/phalcon-debugbar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nayti/phalcon-debugbar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nayti/phalcon-debugbar 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
Debug your SimpleBus EventBus and CommandBus
nice output for debug functions for PHP 5.3
A fork of runcmf/runtracy
DebugBar integration for Winter CMS.
Monolog bridge for PHP Debugbar
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-22