Clockwork

php dev tools integrated to your browser

Clockwork screenshot Clockwork screenshot Clockwork screenshot

What is Clockwork?

Clockwork is a browser extension, providing tools for debugging and profiling your PHP applications, including request data, application log, database queries, routes, visualisation of application runtime and more.

Clockwork uses a server-side component, that gathers all the data and easily integrates with any PHP project, including out-of-the-box support for major frameworks.

Try it out! This very website is Clockwork-enabled, check out the web UI, or download the Chrome or Firefox extension before using it your own applications.

Install the Clockwork library via Composer.

$ composer require itsgoingd/clockwork

If you are running the latest Laravel version, congratulations you are done!

For Laravel versions older than 5.5, you'll need to register the service provider, in your config/app.php:

'providers' => [ ... Clockwork\Support\Laravel\ClockworkServiceProvider::class ]

By default, Clockwork will only be available in debug mode, you can change this and other settings in the configuration file. Use the vendor:publish Artisan command to publish the configuration file into your config directory.

Clockwork comes with a clock() helper function, which provides an easy way to add records to the Clockwork log and events to the timeline.

If you prefer to use a Facade, add following to your config/app.php:

'aliases' => [ ... 'Clockwork' => Clockwork\Support\Laravel\Facade::class, ]

Note: If you are using Laravel route cache, you will need to refresh it using the route:cache Artisan command.

Usage

To interact with the data collected by Clockwork, you will need to

Clockwork comes with a clock() helper function, which provides an easy way to add records to the Clockwork log or events to the timeline.

You can also access Clockwork using the Clockwork facade, resolving from the container app('clockwork') or typehinting Clockwork\Clockwork.

Logging

All data logged using the Laravel log methods will also appear in the Clockwork log tab for the request.

You can also use the Clockwork log directly, with the benefit of rich logging capabilities. You can safely log any variable, from a simple strings to an object.

Logging data to Clockwork can be done using the helper function, which even supports logging multiple values at once

clock(User::first(), auth()->user(), $username)

If you want to specify a log level, you can use the long-form call

clock()->info("User {$username} logged in!")

Timeline

Clockwork adds some general application runtime timeline events for you by default.

To add a custom event to the timeline, you'll need to start an event with an unique name and description first.

clock()->startEvent('twitter-api-call', "Loading users latest tweets via Twitter API")

After executing the tracked block of code, you can end the event, using it's unique name.

clock()->endEvent('twitter-api-call')

Events that are not stopped explicitly will simply finish when the application runtime ends.

Configuration

By default, Clockwork will only be available in debug mode, you can change this and more settings in the configuration file.

You can publish the configuration file using the vendor:publish artisan command to

  • set when should Clockwork be enabled
  • enable or disable the web UI
  • configure how the request metadata is stored
  • set what data should be collected

Latest release

2.0

29 Sep 2017
  • introductory blog post
  • added Web UI
  • added new Laravel cache data source
  • added new Laravel events data source
  • added new more robust metadata storage API
  • added automatic metadata cleanup (defaults to 1 week)
  • added better metadata serialization including class names for objects
  • added PostgreSQL compatibility for the SQL storage (thanks oldskool73)
  • added Slim 3 middleware (thanks sperrichon)
  • added PSR message data source (thanks sperrichon)
  • added Doctrine DBAL data source (thanks sperrichon)
  • changed Clockwork request ids now use dashes instead of dots (thanks Tibbelit)
  • changed Laravel and Lumen integrations to no longer log data for console commands
  • changed simplified the clock Laravel helper (thanks Jergus Lejko)
  • fixed wrong version data logged in SQL storage
  • removed PHP 5.3 support, code style changes
  • removed CodeIgniter support
  • removed ability to register additional data sources via Clockwork config

UPGRADING

  • update the required Clockwork version to ^2.0 in your composer.json
  • PHP 5.3 - no longer supported, you can continue using the latest 1.x version
  • CodeIgniter - no longer supported, you can continue using the lastest 1.x version
  • Slim 2 - update the imported namespace from Clockwork\Support\Slim to Clockwork\Support\Slim\Legacy
  • ability to register additional data sources via Clockwork config was removed, please call app('clockwork')->addDataSource(...) in your own service provider

Read the full changelog