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.2

8 Mar 2018
  • added support for collecting route middleware (thanks Vercoutere)
  • added support for collecting routes and middleware in newer Lumen versions
  • updated Web UI ti match Clockwork Chrome 2.2
  • improved Laravel support to register most event handlers only when collecting data
  • fixed Lumen middleware not being registered automatically (thanks lucian-dragomir)
  • fixed published Lumen config not being loaded

Read the full changelog