同步操作将从 老朱/phalcon-debugbar 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
一个无侵入的Phalcon Framework应用调试/分析工具条
db
服务. 仅支持Phalcon自身的ORM系统entityManager
服务. 仅支持 Doctrine ORM.router
服务.view
服务.request
服务.config
服务.session
服务.log
服务.cache
服务.mail
服务.安装
php composer.phar require --dev snowair/phalcon-debugbar
更新
php composer.phar update snowair/phalcon-debugbar
将应用实例保存为app服务:
$application = new Phalcon\Mvc\Application($di); // 将$di作为构造参数传入 Micro应用也一样: new Phalcon\Mvc\Micro($di);
$di['app'] = $application; // 将应用实例保存到$di的app服务中
在handle()方法前面的位置启动debugbar即可, 例如:
(new Snowair\Debugbar\ServiceProvider())->start();
// 在启动debugbar之后,立即handle应用.
echo $application->handle()->getContent();
下面的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 驱动, 需要安装 mongo 扩展. 默认连接是 mongodb://localhost:27017
, 默认数据库和集合名称都是 debugbar.
当心 baseUri 设置, 你的uri服务必须有正确的 baseUri设置. 然后:
如果你使用apache, 只需要按官方文档在baseUri的目录下增加相应的.htaccess
文件即可.
如果你使用的是nginx, 则需要正确配置location区块,例如:
location @rewrite {
# 把 'baseuri' 字符替换成你项目实际的 baseuri
rewrite ^/baseuri/(.*)$ /baseuri/index.php?_url=/$1;
}
将包内config/debugbar.php
文件复制到你的项目配置目录下, 修改后使用:
(new Snowair\Debugbar\ServiceProvider('your-debugbar-config-file-path'))->start();
\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', $condtion ); // add message only when the second parameter is empty
\PhalconDebug::addMessageIfNotEmpty('condition is not emtpy', $condtion=[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)
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无需任何特殊设置即可支持符合以上习惯的多模块应用.
假如你的服务命名习惯与众不同,则需要手动将缓存或数据库服务绑定到debugbar中, 手动绑定示例代码如下:
// service.php
$di->set('my-db-2',function(...));
$di->set('huan-cun',function(...));
if ( $di->has('debugbar') ) {
$debugbar = $di['debugbar'];
$debugbar->attachDb('my-db-2');
$debugbar->attachCache('huan-cun');
}
依次将配置文件中 collectors
中的各项关闭, 直到问题不再出现, 从而确定是哪个collector的问题, 然后在git@osc 提 issue 反馈
直接提 issue 反馈
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。