Top Related Projects
Provides mechanisms for walking through any arbitrary PHP variable
PHP errors for cool kids
Debugbar for Laravel (Integrates PHP Debug Bar)
Clockwork - php dev tools in your browser - server-side component
Quick Overview
PHP Debug Bar is a powerful debugging tool for PHP applications. It provides a customizable debug bar that displays various information about your application's execution, including performance metrics, database queries, and custom debug data. This library is designed to help developers identify and resolve issues more efficiently during development.
Pros
- Easy integration with popular PHP frameworks like Laravel, Symfony, and Slim
- Highly customizable with support for adding custom collectors and data panels
- Provides real-time performance metrics and detailed execution information
- Minimal impact on application performance when enabled
Cons
- Requires manual configuration for some advanced features
- May expose sensitive information if not properly secured in production environments
- Limited built-in support for asynchronous requests and AJAX calls
- Learning curve for creating custom collectors and panels
Code Examples
- Basic usage:
use DebugBar\StandardDebugBar;
$debugbar = new StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer();
// Add this to your HTML <head>
echo $debugbarRenderer->renderHead();
// Add this at the end of your HTML <body>
echo $debugbarRenderer->render();
- Adding custom messages:
$debugbar['messages']->addMessage('Hello World!');
$debugbar['messages']->addMessage($someObject);
- Measuring execution time:
$debugbar['time']->startMeasure('render', 'Time for rendering');
// ... your code here ...
$debugbar['time']->stopMeasure('render');
- Adding custom data:
$debugbar->addCollector(new DebugBar\DataCollector\ConfigCollector($config));
Getting Started
-
Install PHP Debug Bar using Composer:
composer require maximebf/debugbar
-
Create a new instance of StandardDebugBar in your application:
use DebugBar\StandardDebugBar; $debugbar = new StandardDebugBar(); $debugbarRenderer = $debugbar->getJavascriptRenderer();
-
Add the necessary HTML to your template:
// In your <head> tag echo $debugbarRenderer->renderHead(); // At the end of your <body> tag echo $debugbarRenderer->render();
-
Start using the debug bar in your code:
$debugbar['messages']->addMessage('Debug information'); $debugbar['time']->startMeasure('my_operation', 'My Custom Operation'); // ... your code here ... $debugbar['time']->stopMeasure('my_operation');
Competitor Comparisons
Provides mechanisms for walking through any arbitrary PHP variable
Pros of var-dumper
- More lightweight and focused on variable dumping
- Integrates seamlessly with Symfony framework
- Provides advanced formatting options for complex data structures
Cons of var-dumper
- Limited to variable dumping, lacks broader debugging features
- Requires more setup for standalone use outside Symfony
Code Comparison
php-debugbar:
$debugbar = new DebugBar();
$debugbar->addCollector(new MessagesCollector());
$debugbar['messages']->addMessage('hello world!');
var-dumper:
use Symfony\Component\VarDumper\VarDumper;
VarDumper::dump($variable);
Key Differences
- php-debugbar offers a comprehensive debugging toolbar with various collectors
- var-dumper focuses solely on variable dumping and inspection
- php-debugbar provides a visual interface, while var-dumper outputs to the console or browser
Use Cases
- php-debugbar: Ideal for full-stack PHP applications requiring extensive debugging
- var-dumper: Best for quick variable inspection and Symfony-based projects
Community and Maintenance
- Both projects are actively maintained
- php-debugbar has a larger community and more third-party integrations
- var-dumper benefits from Symfony's ecosystem and regular updates
PHP errors for cool kids
Pros of Whoops
- Lightweight and focused on error handling
- Provides a clean, user-friendly interface for displaying errors
- Easy to integrate with various PHP frameworks
Cons of Whoops
- Limited to error and exception handling
- Lacks performance profiling and debugging features
- Not suitable for production environments without additional configuration
Code Comparison
Whoops:
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
PHP Debugbar:
$debugbar = new \DebugBar\StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer();
echo $debugbarRenderer->renderHead();
echo $debugbarRenderer->render();
Key Differences
- Whoops focuses on error handling and presentation, while PHP Debugbar offers a broader range of debugging tools
- PHP Debugbar provides performance profiling, request information, and database query logging, which Whoops does not
- Whoops is more suitable for development environments, while PHP Debugbar can be used in both development and production with proper configuration
Use Cases
- Choose Whoops for simple error handling and clean error pages in development
- Opt for PHP Debugbar when you need comprehensive debugging tools, including performance profiling and database query analysis
Both tools have their strengths, and the choice depends on your specific debugging needs and project requirements.
Debugbar for Laravel (Integrates PHP Debug Bar)
Pros of laravel-debugbar
- Specifically designed for Laravel, offering seamless integration
- Includes Laravel-specific collectors for routes, views, and events
- Provides a user-friendly interface tailored to Laravel developers
Cons of laravel-debugbar
- Limited to Laravel applications, not suitable for other PHP projects
- May have a slightly higher performance impact due to Laravel-specific features
- Requires more setup and configuration compared to the more generic php-debugbar
Code Comparison
php-debugbar:
$debugbar = new DebugBar();
$debugbar->addCollector(new MessagesCollector());
$debugbar->addCollector(new PhpInfoCollector());
$debugbar->addCollector(new RequestDataCollector());
$renderer = $debugbar->getJavascriptRenderer();
laravel-debugbar:
// In config/app.php
'providers' => [
// ...
Barryvdh\Debugbar\ServiceProvider::class,
],
'aliases' => [
// ...
'Debugbar' => Barryvdh\Debugbar\Facade::class,
],
The php-debugbar requires manual setup and collector addition, while laravel-debugbar is configured through Laravel's service provider and facade system, demonstrating its tight integration with the framework.
Clockwork - php dev tools in your browser - server-side component
Pros of Clockwork
- Lightweight and less intrusive, with minimal impact on application performance
- Provides a clean, modern interface with a focus on simplicity and ease of use
- Offers built-in support for popular PHP frameworks like Laravel and Lumen
Cons of Clockwork
- Less extensive customization options compared to PHP Debugbar
- Fewer out-of-the-box data collectors and panels
Code Comparison
PHP Debugbar:
$debugbar = new DebugBar();
$debugbar->addCollector(new DebugBar\DataCollector\MessagesCollector());
$debugbar->addCollector(new DebugBar\DataCollector\PhpInfoCollector());
$debugbar->addCollector(new DebugBar\DataCollector\RequestDataCollector());
$debugbarRenderer = $debugbar->getJavascriptRenderer();
Clockwork:
use Clockwork\Support\Vanilla\Clockwork;
$clockwork = Clockwork::init();
$clockwork->startEvent('custom_event', 'Custom event description');
// Your code here
$clockwork->endEvent('custom_event');
Both PHP Debugbar and Clockwork are powerful debugging tools for PHP applications. PHP Debugbar offers more extensive customization and a wider range of data collectors, making it suitable for complex debugging scenarios. Clockwork, on the other hand, provides a more streamlined experience with a focus on simplicity and performance, making it an excellent choice for developers who prefer a lightweight solution with minimal setup.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
PHP Debug Bar
Displays a debug bar in the browser with information from php.
No more var_dump()
in your code!
Features:
- Generic debug bar
- Easy to integrate with any project
- Clean, fast and easy to use interface
- Handles AJAX request
- Includes generic data collectors and collectors for well known libraries
- The client side bar is 100% coded in javascript
- Easily create your own collectors and their associated view in the bar
- Save and re-open previous requests
- Very well documented
Includes collectors for:
Checkout the demo for examples and phpdebugbar.com for a live example.
Integrations with other frameworks:
- Laravel
- Atomik
- XOOPS
- Zend Framework 2
- Phalcon
- SilverStripe
- Grav CMS
- TYPO3
- Joomla
- Drupal
- October CMS
- Framework-agnostic middleware and PSR-7 with php-middleware/phpdebugbar
- Dotkernel Frontend Application
(drop me a message or submit a PR to add your DebugBar related project here)
Installation
The best way to install DebugBar is using Composer with the following command:
composer require maximebf/debugbar
Quick start
DebugBar is very easy to use and you can add it to any of your projects in no time.
The easiest way is using the render()
functions
<?php
// Require the Composer autoloader, if not already loaded
require 'vendor/autoload.php';
use DebugBar\StandardDebugBar;
$debugbar = new StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer();
$debugbar["messages"]->addMessage("hello world!");
?>
<html>
<head>
<?php echo $debugbarRenderer->renderHead() ?>
</head>
<body>
...
<?php echo $debugbarRenderer->render() ?>
</body>
</html>
The DebugBar uses DataCollectors to collect data from your PHP code. Some of them are
automated but others are manual. Use the DebugBar
like an array where keys are the
collector names. In our previous example, we add a message to the MessagesCollector
:
$debugbar["messages"]->addMessage("hello world!");
StandardDebugBar
activates the following collectors:
MemoryCollector
(memory)MessagesCollector
(messages)PhpInfoCollector
(php)RequestDataCollector
(request)TimeDataCollector
(time)ExceptionsCollector
(exceptions)
Learn more about DebugBar in the docs.
Demo
To run the demo, clone this repository and start the Built-In PHP webserver from the root:
php -S localhost:8000
Then visit http://localhost:8000/demo/
Testing
To test, run php vendor/bin/phpunit
.
To debug Browser tests, you can run PANTHER_NO_HEADLESS=1 vendor/bin/phpunit --debug
. Run vendor/bin/bdi detect drivers
to download the latest drivers.
Top Related Projects
Provides mechanisms for walking through any arbitrary PHP variable
PHP errors for cool kids
Debugbar for Laravel (Integrates PHP Debug Bar)
Clockwork - php dev tools in your browser - server-side component
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot