How can I get a debug toolbar for my Expressive application?

Many modern frameworks and applications provide debug toolbars: in-browser toolbars to provide profiling information of the request executed. These can provide invaluable details into application objects, database queries, and more. As an Expressive user, how can you get similar functionality?

Zend Server Z-Ray

Zend Server ships with a tool called Z-Ray, which provides both a debug toolbar and debug console (for API debugging). Z-Ray is also currently available as a standalone technology preview, and can be added as an extension to an existing PHP installation.

When using Zend Server or the standalone Z-Ray, you do not need to make any changes to your application whatsoever to benefit from it; you simply need to make sure Z-Ray is enabled and/or that you've setup a security token to selectively enable it on-demand. See the Z-Ray documentation for full usage details.


Another option is bitExpert's prophiler-psr7-middleware. This package wraps fabfuel/prophiler, which provides a PHP-based profiling tool and toolbar; the bitExpert package wraps this in PSR-7 middleware to make consumption in those paradigms trivial.

To add the toolbar middleware to your application, use composer:

$ composer require bitExpert/prophiler-psr7-middleware

From there, you will need to create a factory for the middleware, and add it to your middleware pipeline. Stephan Hochdörfer, author of the package, has written a post detailing these steps.

Use locally!

One minor change we recommend over the directions Stephan provides is that you configure the factory and middleware in the config/autoload/middleware-pipeline.local.php file, vs the .global version. Doing so enables the middleware and toolbar only in the local environment — and not in production, where you likely do not want to expose such information!


php-middleware/php-debug-bar provides a PSR-7 middleware wrapper around maximebf/php-debugbar, a popular framework-agnostic debug bar for PHP projects.

First, install the middleware in your application:

$ composer require php-middleware/php-debug-bar

This package supplies a config provider, which could be added to your config/config.php when using zend-config-aggregator or expressive-config-manager. However, because it should only be enabled in development, we recommend creating a "local" configuration file (e.g., config/autoload/php-debugbar.local.php) when you need to enable it, with the following contents:

use PhpMiddleware\PhpDebugBar\ConfigProvider;

$provider = new ConfigProvider();
return $provider();

Use locally!

Remember to enable PhpMiddleware\PhpDebugBar\ConfigProvider only in your development enviroments!