thepocket006/codeigniter-debugbar
Composer 安装命令:
composer require thepocket006/codeigniter-debugbar
包简介
CodeIgniter Debug Bar using PHP Debug Bar.
关键字:
README 文档
README
- PHP 5.5+ (recommended by CodeIgniter)
- CodeIgniter 3.1.x
Installation
Create composer.json file in your application's root if there is none. Add the following text in the file:
{
"require": {
"thepocket006/codeigniter-debugbar": "dev-master"
}
}
Enable Composer (locate in application/config/config.php) :
$config['composer_autoload'] = realpath(APPPATH.'../vendor/autoload.php');
Enable Debugbar package (locate in application/config/autoload.php) :
$autoload['packages'] = array(APPPATH.'third_party/codeigniter-debugbar');
if you want to log messages and exceptions you can also load console library
$autoload['libraries'] = array('console');
To use it.
$this->console->exception(new Exception('test exception')); $this->console->debug('Debug message'); $this->console->info('Info message'); $this->console->warning('Warning message'); $this->console->error('Error message');
Then, enable the profiler like normal.
$this->output->enable_profiler(TRUE);
To complete the installation, add the following header tags :
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js"></script> <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/styles/github.min.css"> <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
Configuration
Duplicate configuration file located in application/third_party/codeigniter-debugbar/config/profiler.php to application/config/profiler.php.
To configure the profiler, read CodeIgniter profiler documentation.
CodeIgniter Debug Bar adds 4 new sections :
- CodeIgniter infos : Display informations about CodeIgniter (version, environment and locale).
- Messages : Display messages (Console library must be loaded).
- Exceptions : Display exceptions (Console library must be loaded).
- Included files : Display included or required files.
You can configure PHP Debug Bar directly into the profiler configuration file, read PHP Debug Bar documentation for more information.
Advanced configuration
AJAX
By default ajax debug data are send through headers but if you are sending a lot of data it may cause problems with your browser. If you set open_handler_url in the configuration file, it will use a storage handler and the open handler to load the data after an ajax request.
Here is an example of an open_handler_url setting.
$config['open_handler_url'] = get_instance()->config->site_url('debug/open_handler');
This code will be in application/controllers/Debug.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); use DebugBar\DebugBar; use DebugBar\OpenHandler; use DebugBar\Storage\FileStorage; class Debug extends CI_Controller { public function open_handler() { $this->output->enable_profiler(FALSE); $this->config->load('profiler', TRUE); $path = $this->config->item('cache_path', 'profiler'); $cache_path = ($path === '') ? APPPATH.'cache/debugbar/' : $path; $debugbar = new DebugBar(); $debugbar->setStorage(new FileStorage($cache_path)); $openHandler = new OpenHandler($debugbar); $data = $openHandler->handle(NULL, FALSE, FALSE); $this->output ->set_content_type('application/json') ->set_output($data); } }
Output
There is two options that can be use to handle custom profiler output.
display_assets: Whether display content's assets (default: TRUE)display_javascript: Whether display inline script (default: TRUE)
If you set display_assets to false you have to handle assets output manually, for this purpose you can use CI_Profiler::css_assets() and CI_Profiler::js_assets() they behave exactly like JavascriptRenderer::dumpJsAssets() and JavascriptRenderer::dumpJsAssets() see PHP Debug Bar documentation .
If you set display_javascript to false you have to handle inline script manually, for this purpose you can use CI_Profiler::inline_script() (IMPORTANT : It display inline script with <script> tags !).
Here is an exmple of how you can use it:
<?php /** * This method handle custom profiler output if profiler is enable, except * for json output. */ public function _output($output) { if (stripos($this->output->get_content_type(), 'json') !== false) { echo $output; return; } if ($this->output->enable_profiler) { $this->appendAssets() ->appendBody('<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>') ->appendBody('<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js"></script>') ->appendHeader('<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/styles/github.min.css">') ->appendHeader('<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">') ->appendInlineScript(trim(str_replace(['<script type="text/javascript">', '</script>'], ['', ''], CI_Profiler::inline_script()))); } echo $output; } /** * This method will write PhpDebugbar assets files if they don't exist in * public directory and add them to the output with custom functions. */ protected function appendAssets() { $files = ['css_assets' => 'public/css/PhpDebugbar.css', 'js_assets' => 'public/js/PhpDebugbar.js']; foreach ($files as $function => $filepath) { if (!file_exists(FCPATH.$filepath)) { forward_static_call_array(array('CI_Profiler', $function), array(FCPATH.$filepath)); } } return $this->appendBody('<script type="text/javascript" src="'.base_url($files['js_assets']).'"></script>') ->appendHeader('<link rel="stylesheet" href="'.base_url($files['css_assets']).'">'); }
IMPORTANT : Functions to handle profiler output can only be use in CodeIgniter controller function _output().
License
The MIT License (MIT)
Copyright (c) 2014-2017 Anthony Tansens
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
thepocket006/codeigniter-debugbar 适用场景与选型建议
thepocket006/codeigniter-debugbar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「debug」 「codeigniter」 「profiler」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 thepocket006/codeigniter-debugbar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thepocket006/codeigniter-debugbar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 thepocket006/codeigniter-debugbar 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
Debug your SimpleBus EventBus and CommandBus
nice output for debug functions for PHP 5.3
The CodeIgniter Redis package
Analysis module for finding problematical shop data.
Twig extensions for Tracy Debugger
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-15