A powerful debug and profilers tool for the Phalcon Framework

Overview

Latest Stable Version Total Downloads Latest Unstable Version License

Phalcon Debugbar

Integrates PHP Debug Bar with Phalcon Framework.

中文说明

Features

  1. Normal request capturing
  2. Ajax request capturing
  3. Redirect request chain capturing
  4. Simple App, Multi module App and Micro App support
  5. Data collected persistent : save to Local File or MongoDB, or ElasticSearch
  6. Data storaged by sessionid, it's more firendly for team development.
  7. You can close inject debugbar, and on a new browser tab, visit /_debugbar/open to see data(and it alse can be disabled).
  8. Whoops Integration, and debugbar works well with it.
  9. 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 db service. Only for Phalcon ORM.
  • DoctrineCollector: Capture each SQL statement in Doctrine, measure spent time of each SQL.
    • collect information from the entityManager service. Only for Doctrine ORM.
  • RouteCollector: Show Route info of current request.
    • collect information from the router service.
  • ViewCollector: Show all the rendered templates, measure spent time of each template, show all the templates variables.
    • collect information from the view service.
  • PhalconRequestCollector: Show request headers, cookies, server variables, response headers, querys, post data,raw body
    • collect information from the request service.
  • ConfigCollector: Show the data in the config service.
    • collect information from the config service.
  • SessionCollectior: Show session data
    • collect information from the session service.
  • SwiftMailCollector: mailer info
    • collect information from the mail service.
  • LogsCollectors: Show logs of current request. Support Phalcon\Logger and Monolog
    • collect information from the log service.
  • CacheCollectors: Show caches summary (saved,gets,incs,decs,failds), and each cache operation detail.
    • collect information from the cache service.

Quick start

composer

  • install

    php composer.phar require --dev snowair/phalcon-debugbar
    
  • update

    php composer.phar update snowair/phalcon-debugbar
    

Modify index.php

  1. 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
  2. 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();
  3. 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:

  1. All the services for cache has a name contain cache.
  2. All the services for db has a name start with db or end with db.
  3. 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 uri service 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


Screenshot


Screenshot


Screenshot


Screenshot


Screenshot


Screenshot


Screenshot


Screenshot


Screenshot


Screenshot


Screenshot

Comments
  • Incorrect asset URI rendered

    Incorrect asset URI rendered

    Since commit 95efd03cad7ec92c836cbabc7dd5bdec9303b1dd phalcon-debugbar always renders root asset URIs (ie. /_debugbar/assets...) instead of using the application baseUri.

    This disallows using phalcon-debugbar on any application that is not hosted at the root of its domain.

    Contrary to what the commit message seems to indicate, it did work perfectly before. IMO it should be reverted, I think @bluetec had a configuration issue that had nothing to do with phalcon-debugbar itself.

    bug 
    opened by njoyard 8
  • Ajax display message

    Ajax display message

    i want to see a message from ajax request. In ajax request i set a message or info to display in debugbar but it will not appeare.

    how i can do that?

    In debug bar I can't see ajax request.

    Thanks in advantage

    opened by galliroberto 6
  • debugbar autoloader

    debugbar autoloader

    I have not seen how to load debugbar with Phalcon autoloader (registerDirs or registerNamespaces) so I use composer autoloader. This works, but is it the right solution? The documentation says nothing about it.

    What PSR specification is used?

    opened by jcheron 5
  • 404 error for static files

    404 error for static files

    I use default INVO with your plug-in, but receive errors:

    "NetworkError: 404 Not Found - http://test.loc/_debugbar/assets/stylesheets?1445286912"
    stylesh...5286912
    "NetworkError: 404 Not Found - http://test.loc/_debugbar/assets/javascript?1445286912"
    javascr...5286912
    "NetworkError: 404 Not Found - http://test.loc/_debugbar/assets/stylesheets?1445286912"
    stylesh...5286912
    "NetworkError: 404 Not Found - http://test.loc/_debugbar/assets/javascript?1445286912"
    

    my public.index.php

    <?php
    error_reporting(E_ALL);
    
    use Phalcon\Mvc\Application;
    use Phalcon\Config\Adapter\Ini as ConfigIni;
    
    try {
        define('APP_PATH', realpath('..') . '/');
    
        $config = new ConfigIni(APP_PATH . 'app/config/config.ini');
        if (is_readable(APP_PATH . 'app/config/config.ini.dev')) {
            $override = new ConfigIni(APP_PATH . 'app/config/config.ini.dev');
            $config->merge($override);
        }
        require APP_PATH . 'app/config/loader.php';
        require APP_PATH . 'app/config/services.php';
    
        $application = new Application($di);
        $di['app'] = $application;
        (new Snowair\Debugbar\ServiceProvider())->start();
    
        echo $application->handle()->getContent();
    } catch (Exception $e){
        echo $e->getMessage() . '<br>';
        echo '<pre>' . $e->getTraceAsString() . '</pre>';
    }
    

    my app/confing/loader.php

    <?php
    require_once __DIR__ . '/../../vendor/autoload.php';
    $loader = new \Phalcon\Loader();
    $loader->registerDirs(
        array(
            APP_PATH . $config->application->controllersDir,
            APP_PATH . $config->application->pluginsDir,
            APP_PATH . $config->application->libraryDir,
            APP_PATH . $config->application->modelsDir,
            APP_PATH . $config->application->formsDir,
        )
    )->register();
    

    Any ideas?

    opened by panaceya 5
  • Get 502 Bad Gateway when AJAX Request

    Get 502 Bad Gateway when AJAX Request

    Phalcon version: 1.3.6 Php version : 5.5.19

    echo json_encode($users->toArray());
    

    When we return the json format as response to Ajax, it will occur error 502: Bad Gateway. If we disable the phalcon-debugbar, everything is fine.

    I also tested it in phalcon version 2.0.2, but it was fine.

    opened by yewjs 5
  • Exception when enable cache module

    Exception when enable cache module

    Hi,

    Firstly, I want to thank You for great module, it's really helpful :)

    But I got a little error, I enabled cache module and got exception:

    Phalcon\Di\Exception: Call to undefined method or service 'createProxy' 
    /vagrant/www/vendor/snowair/phalcon-debugbar/src/PhalconDebugbar.php (265)
    

    My configuration of cache DI is:

    $di->setShared('cache', function () {
    $cache = new Multiple([
        $this->get('redis'),
    ]);
    
    return $cache;
    });
    
    
    $di->setShared('redis', function () {
    $frontCache = new DataFrontend([
        'lifetime' => 3600 * 24 * 7
    ]);
    
    $redis = new \Phalcon\Cache\Backend\Redis($frontCache, [
        'host' => $this->get('config')->redis->host,
        'port' => $this->get('config')->redis->port,
        'auth' => $this->get('config')->redis->password,
        'statsKey' => '_PHCR'
    ]);
    
    return $redis;
    });
    

    What is wrong?

    opened by Zaszczyk 4
  • PHP Debugbar is not working

    PHP Debugbar is not working

    Hi All, Sorry, My English is not good. I have add phalcon-debugbar from this link: https://github.com/snowair/phalcon-debugbar. but it is not working. When I run, In my console is display: 2015-10-20_162412 I found error: dashboard:449 GET http://dashboard.somo.local_debugbar/assets/stylesheets?1445331526 net::ERR_NAME_NOT_RESOLVED dashboard:450 GET http://dashboard.somo.local_debugbar/assets/javascript?1445331525 net::ERR_NAME_NOT_RESOLVED dashboard:453 Uncaught ReferenceError: PhpDebugBar is not defined(anonymous function) @ dashboard:453 sb-admin-2.js:2 Uncaught TypeError: $ is not a function

    How to I can fix it ?

    opened by gpphong8th2 4
  • Using doctrine with Phalcon and phalcon-debugbar

    Using doctrine with Phalcon and phalcon-debugbar

    Hi,

    I'm creating a Phalcon project, but instead of using Phalcon's native database access I'm using doctrine, since I'm more comfortable with the data-mapper pattern rather than the active record one.

    Anyway, I'm using your awesome phalcon-debugbar but I'm not able to see database information.

    I went to the original PHP Debug Bar documentation to look for a solution, but it doesn't seem to work.

    What I did was, following the mentioned docs and your instructions, to insert this lines of code in my bootstrap:

            $application = new Phalcon\Mvc\Application($di);
            // CONFIGURE DEBUGBAR
            $di['app'] = $application;
            (new ServiceProvider(APP_PATH . 'config/debugbar.php'))->start();
            $em = $di->get('entityManager');
            $debugStack = new DebugStack();
            $em->getConnection()->getConfiguration()->setSQLLogger($debugStack);
            $debugbar = $di->get('debugbar');
            $debugbar->addCollector(new DoctrineCollector($debugStack));
            echo $application->handle()->getContent();
    

    Is there any way that I can manage to see the database tab using doctrine in Phalcon?

    Thanks for the awesome job, and thanks in advance for your help

    opened by antonienko 4
  • Exception: The argument is not initialized or iterable()

    Exception: The argument is not initialized or iterable()

    Hi,

    I was triying to setup the debugbar with the Phalcon 2.0 release, it throws a Exception: The argument is not initialized or iterable() phalcon/http/response/headers.zep (98)

    Can't find the error line that throws the exception from debugbar, it appears to be after the $debugbar->modifyResponse($response); but can't follow it after that.

    opened by Surt 4
  • PHP 7 Support

    PHP 7 Support

    From what I could see, PHP 7 support is currently blocked by third party libraries, whoops and php-debugbar.

    For whoops, it's just needed to upgrade to v2, for php-debugbar we need to wait they add support for PHP 7: https://github.com/maximebf/php-debugbar/issues/264

    opened by JCMais 2
  • Activating collectors

    Activating collectors

    i have added following line in public/index.php but nothing effected. What is the proper way to add collectors.

    $di['debugbar']->addCollector(new Snowair\Debugbar\DataCollector\PhalconRequestCollector);

    opened by metehan 2
  • [SOLUTION]  Warning: Illegal offset type in /vendor/snowair/phalcon-debugbar/src/PhalconDebugbar.php on line 419 / 432

    [SOLUTION] Warning: Illegal offset type in /vendor/snowair/phalcon-debugbar/src/PhalconDebugbar.php on line 419 / 432

    Hi A new bug and the solution. For this warning : Warning: Illegal offset type in /vendor/snowair/phalcon-debugbar/src/PhalconDebugbar.php on line 419 replace line 419

    $templates[$viewFilePath]['startTime'] = microtime(true);
    

    with

    if(is_array($viewFilePath)){
                    foreach($viewFilePath as $infos_path){
                        $templates[$infos_path]['startTime'] = microtime(true);
                    }
    }else{
     $templates[$viewFilePath]['startTime'] = microtime(true);
    }
    

    Do the same line 432 (line 441 after previous change)

    See you

    opened by OrangeTanguine 0
  • [SOLUTION] Phalcon 4.1.0 - \Profiler::startProfile() must be of the type string, null given

    [SOLUTION] Phalcon 4.1.0 - \Profiler::startProfile() must be of the type string, null given

    Hi ! A new bug with the new version of Phalcon (4.1.0). You can have this error :

    Fatal error: Uncaught TypeError: Argument 1 passed to Snowair\Debugbar\Phalcon\Db\Profiler::startProfile() must be of the type string, null given, called in /data/www/project.com/vendor/snowair/phalcon-debugbar/src/PhalconDebugbar.php on line 710 and defined in /data/www/project.com/vendor/snowair/phalcon-debugbar/src/Phalcon/Db/Profiler.php on line 70
    

    You can read the reason in the changelog of phalcon : https://github.com/phalcon/cphalcon/blob/master/resources/CHANGELOG-4.1.md Changed Phalcon\Db\Adapter\*::getRealSQLStatement() to return the full SQL query with parameters #12196

    SOLUTION : /vendor/snowair/phalcon-debugbar/src/PhalconDebugbar.php on line 706 change

     $sql = $db->getRealSQLStatement();
    

    to

    $sql = $db->getSQLStatement();
    

    And it works ;-)

    See you !

    opened by OrangeTanguine 0
  • doesn't work

    doesn't work

    phalcon 3.4, php 7.1, clean install:

    PHP Fatal error: Default value for parameters with a class type hint can only be NULL in ...../vendor/symfony/var-dumper/Dumper/CliDumper.php on line 61

    opened by devnes 0
  • Static url on subdomain

    Static url on subdomain

    Hi.

    I have problem with using debugbar, when i have set "url static" on other (sub) domain.

    Earlier, I used a static url within the same domain (statics were in the "/cdn/" folder). In order for assets and open handler to be read correctly, I redirected everything containing _debugbar to "baseUrl + /_debugbar*" and it worked.

    My prev uri settings look this: baseUrl: / staticsUrl: /cdn/

    After changing the url of the statics to the subdomain, debugbar generates addresses to the resources in the following way: http://domain/http://cdn.domain/_debugbar/assets/stylesheets?m=1544445135&module (or http://domain/cdn.domain/ if i not set protocol in address)

    My uri settings after changing to subdomain: baseUrl: / staticsUrl: //cdn.domain/

    Ok. In this moment, assets (js and css) loaded success, because everything after _debugbar is redirected to the base address (domain/ debugbar*_). It follows from this that for assets, the address is built in the following way: src/JsRender.php

     $baseuri = rtrim($this->url->getBasePath(),'/').'/';
        $html .= sprintf(
            '<link rel="stylesheet" type="text/css" href="%s?m='.$m.'&%s">' . "\n",
            $baseuri.ltrim($this->url->getStatic(array('for'=>'debugbar.assets.css')),'/'),
            $time
        );
    

    src/PhalconDebugbar.php Unfortunately, the address "open handler" is created directly from statics::

    $openHandlerUrl = $this->di['url']->getStatic( array('for'=>'debugbar.openhandler') );
    

    and resulting in the creation of a non-existent address to an external domain resource statics: http://cdn.domain/_debugbar/open?op=get&id=xxxxxxxxxxxxxxxxxxxxxxxx

    Since the resources for debugbar are generated by the controller, would not it be better to read them directly from url->get instead of url->getStatic? Is it not a mistake to read open handler from an address intended for static, or should the address to it be generated in the same way as in the case of assets?

    Can I expect the next version, uri configuration options for debugbar?

    opened by Xerphis 0
  •  Warning: get_class() expects parameter 1 to be object

    Warning: get_class() expects parameter 1 to be object

    With PHP7.0.30, we have a warning bug : ( ! ) Warning: get_class() expects parameter 1 to be object, null given in /usr/share/nginx/html/projectname/vendor/snowair/phalcon-debugbar/src/DataCollector/RouteCollector.php on line 59

    Bug Line : $result['Controller'] = get_class( $controller_instance = $dispatcher->getActiveController());

    Fix : $result['Controller'] = $dispatcher->getActiveController() != null ? get_class( $controller_instance = $dispatcher->getActiveController()) : $controller_instance ="";

    Thks !

    opened by OrangeTanguine 0
Owner
Yajie Zhu
Yajie Zhu
Debug - The Debug component provides tools to ease debugging PHP code.

Debug Component CAUTION: this component is deprecated since Symfony 4.4. Instead, use the ErrorHandler component. The Debug component provides tools t

Symfony 7.3k Jan 8, 2023
A Phalcon paginator adapter for Phalcon Collections

Phalcon Collection Paginator A Phalcon paginator adapter for Phalcon Collections Why create this? Being familiar with the various Pagination data adap

Angel S. Moreno 2 Oct 7, 2022
Setupify is a Phalcon provisioning and development tool.

Setupify Provisioning Tool WARNING: Setupify is currently in a state of experimentation. Use tag release. Setupify is a collection of bash scripts for

Perch Labs 3 Oct 7, 2022
Time registration tool build with Phalcon

PhalconTime Application PhalconTime is a timekeeping tool that helps you track hours spend on clients and projects. Please write me if you have any fe

null 6 Oct 7, 2022
Debug component from Zend Framework

zend-debug Zend\Debug is a component that help the debugging of PHP applications. In particular it offers a static method Zend\Debug\Debug::dump() tha

Zend Framework 12 Jan 29, 2020
Implementation of an API application using the Phalcon Framework

phalcon-api Sample API using Phalcon Implementation of an API application using the Phalcon Framework https://phalcon.io Installation Clone the projec

The Phalcon PHP Framework 81 Dec 15, 2022
Easy Repository pattern for PHP Phalcon framework.

Phalcon Repositories Introduction Phalcon Repositories lets you easily build repositories for your Phalcon models, for both SQL and Mongo drivers. PHP

Michele Angioni 18 Oct 7, 2022
Incubator adapters/functionality for the Phalcon PHP Framework

Phalcon Incubator This is a repository to publish/share/experiment with new adapters, prototypes or functionality that can potentially be incorporated

The Phalcon PHP Framework 735 Dec 27, 2022
CMS based on Phalcon PHP Framework with modular structure

Yona CMS Yona CMS - open source content management system (CMS). Written in Phalcon PHP Framework (version 3.x supported) Has a convenient modular str

Alexander Torosh 369 Dec 27, 2022
Invo - Sample application for the Phalcon PHP Framework

INVO Application Phalcon is a web framework delivered as a C extension providing high performance and lower resource consumption. This is a sample app

The Phalcon PHP Framework 344 Dec 14, 2022
Album-o-rama - Sample application for the Phalcon PHP Framework.

Album O'Rama Phalcon PHP is a web framework delivered as a C extension providing high performance and lower resource consumption. This is a sample app

The Phalcon PHP Framework 84 Oct 7, 2022
Magento 2 Debug Helper Module for easy debugging with Xdebug and PHPStorm or any other IDE

Magento 2 Debug Helper Information and Usage Magento 2 Debug Helper Module usage with PHPStorm and Xdebug Installation To install the Magento 2 Debug

Dmitry Shkoliar 13 May 24, 2022
Debug with Ray to fix problems faster

Debug with Ray to fix problems faster This package can be installed in any PHP application to send messages to the Ray app. The desktop app: can be us

Spatie 458 Dec 27, 2022
Hook-logger-plugin - Debug WordPress action / filter hooks.

hook-logger-plugin Easily debug WordPress action / filter hooks, finding where actions are called from and understanding the flow of execution. This p

bruce aldridge 4 Feb 5, 2022
Xr - Lightweight debug server utility built on ReactPHP.

XR ?? Subscribe to the newsletter to don't miss any update regarding Chevere. XR is a dump server utility built on top of ReactPHP. Features ✨ Dump si

Chevere 195 Dec 17, 2022
Frog - A new way to debug in PHP

Frog - A new way to debug in PHP There are situations where you want to show information of variables in PHP. While print_r, var_dump and var_export a

Tran Ngoc Tuan Anh 19 Nov 3, 2022
Extends the Debug Bar plugin for the Sophi.io Site Automation service.

Debug Bar for Sophi Extends the Debug Bar plugin for the Sophi.io Site Automation service. Requirements PHP 7.4+ WordPress 5.6+ Sophi 1.1.0+ Debug Bar

10up 2 Jun 22, 2022
A few Fat-Free specific extensions for Tracy Debugger to help debug your code quickly.

Fat-Free Tracy Extensions This is a set of extensions to make working with Fat-Free a little richer. F3 - Analyze all hive variables. Database - Analy

Austin 6 Nov 17, 2022