Clockwork - php dev tools in your browser - server-side component

Last update: May 18, 2022

Clockwork is a development tool for PHP available right in your browser. Clockwork gives you an insight into your application runtime - including request data, performance metrics, log entries, database queries, cache queries, redis commands, dispatched events, queued jobs, rendered views and more - for HTTP requests, commands, queue jobs and tests.

This repository contains the server-side component of Clockwork.

Check out on the Clockwork website for details.

Installation

Install the Clockwork library via Composer.

$ composer require itsgoingd/clockwork

Congratulations, you are done! To enable more features like commands or queue jobs profiling, publish the configuration file via the vendor:publish Artisan command.

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

Read full installation instructions on the Clockwork website.

Features

Collecting data

The Clockwork server-side component collects and stores data about your application.

Clockwork is only active when your app is in debug mode by default. You can choose to explicitly enable or disable Clockwork, or even set Clockwork to always collect data without exposing them for further analysis.

We collect a whole bunch of useful data by default, but you can enable more features or disable features you don't need in the config file.

Some features might allow for advanced options, eg. for database queries you can set a slow query threshold or enable detecting of duplicate (N+1) queries. Check out the config file to see all what Clockwork can do.

There are several options that allow you to choose for which requests Clockwork is active.

On-demand mode will collect data only when Clockwork app is open. You can even specify a secret to be set in the app settings to collect request. Errors only will record only requests ending with 4xx and 5xx responses. Slow only will collect only requests with responses above the set slow threshold. You can also filter the collected and recorded requests by a custom closure. CORS pre-flight requests will not be collected by default.

New in Clockwork 4.1, artisan commands, queue jobs and tests can now also be collected, you need to enable this in the config file.

Clockwork also collects stack traces for data like log messages or database queries. Last 10 frames of the trace are collected by default. You can change the frames limit or disable this feature in the configuration file.

Viewing data

Web interface

Open your.app/clockwork to view and interact with the collected data.

The app will show all executed requests, which is useful when the request is not made by browser, but for example a mobile application you are developing an API for.

Browser extension

A browser dev tools extension is also available for Chrome and Firefox:

Toolbar

Clockwork now gives you an option to show basic request information in the form of a toolbar in your app.

The toolbar is fully rendered client-side and requires installing a tiny javascript library.

Learn more on the Clockwork website.

Logging

You can log any variable via the clock() helper, from a simple string to an array or object, even multiple values:

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

The clock() helper function returns it's first argument, so you can easily add inline debugging statements to your code:

User::create(clock($request->all()))

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

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

Timeline

Timeline gives you a visual representation of your application runtime.

To add an event to the timeline - start it with a description, execute the tracked code and finish the event. A fluent api is available to further configure the event.

// using timeline api with begin/end and fluent configuration
clock()->event('Importing tweets')->color('purple')->begin();
    ...
clock()->event('Importing tweets')->end();

Alternatively you can execute the tracked code block as a closure. You can also choose to use an array based configuration instead of the fluent api.

// using timeline api with run and array-based configuration
clock()->event('Updating cache', [ 'color' => 'green' ])->run(function () {
    ...
});

Read more about available features on the Clockwork website.

GitHub

https://github.com/itsgoingd/clockwork
Comments
  • 1. Multiple X-Clockwork-Id header

    Our backend makes multiple call in one request to our API.

    For example for a /user backend call, our backend will call 2 API route, one for the user languages and an other one for the user preferences.

    So we have a list of X-Clockwork-id unique header, but it's not handled by the Chrome extension.

    Is it planned to add this feature?

    Reviewed by L3o-pold at 2018-03-16 15:53
  • 2. array_combine(): Both parameters should have an equal number of elements is back

    It happens randomly in Grav 1.7 admin with v4.1.7 …/vendor/itsgoingd/clockwork/Clockwork/Storage/FileStorage.php line 285

    Parameters for me are:

    array:8 [▼
      0 => "id"
      1 => "time"
      2 => "method"
      3 => "uri"
      4 => "controller"
      5 => "responseStatus"
      6 => "responseDuration"
      7 => "type"
    ]
    
    array:11 [▼
      0 => "1582548042-5053-611931862"
      1 => "1582548042.501"
      2 => "POST"
      3 => "/admin/pages/core/modular/_callout.json1582891095-7666-622537541"
      4 => "1582891095.76"
      5 => "GET"
      6 => "/plugins/shortcode/ui"
      7 => ""
      8 => "200"
      9 => "87.949991226196"
      10 => "request"
    ]
    
    Reviewed by mahagr at 2020-08-28 10:54
  • 3. Symfony 4/5 support does not work

    Hello,

    First, thanks for this project that seems really cool for debugging application.

    Now, the issue i've found with either Symfony 4 (4.4.3) or Symfony 5 (5.0.3). The code need some patches to be really up and running ! (I could provide some PR to solve it)

    I've tested either Firefox or Chrome extensions with same results :

    • Extension display always
    Error loading request metadata.
    Server returned an error response.
    

    While, i found no error in Symfony Profiler or error_log file.

    How can we debug and see what happens. Help will be greatly appreciated.

    Some screenshots from Chrome 79.0.3945.130 ((64 bits) I've also tested it with Firefox 72.0.2 (64 bits) that give the same results.

    clockwork_chrome_symfony symfony_profiler_2840c9

    Reviewed by llaville at 2020-01-29 14:23
  • 4. Clockwork Enhancement Ideas

    Apologies if this is not the correct place, but the Feature Ideas issue #321 was closed.

    We are incorporating Clockwork in Grav CMS as an option over the existing PHPDebugBar. We've already got it added and working in our 1.7 branch (https://github.com/getgrav/grav/tree/1.7), but we've run into a few issues and limitations. We're using the latest dev-master version and I know you are working on the 4.0 release so maybe some things could be taken into consideration for that release?

    • Grav is flat file based, so references to database timings are not relevant. Would be nice if the extension didn't display those timings if they were not set, or perhaps an option to remove them?

    Image 2019-06-05 at 10 38 59 AM

    • An option to control the order of the Clockwork tabs would be a nice to have as we like to put the Performance tab first, before Request.

    • The expandable tree view of data in the Log tab is great but would be awesome to have more options (like open all nodes, close all nodes, etc) as it's useful to output complex data in there, but a pain to dig in on every request.

    • Possibility to have count badges on tabs? This would be very useful to show at a glance the number of items in a custom tab.

    • Profiler support is cool, but the Xdebug profiler is super slow compared to XHProf. Support for XHProf for profiler would be a welcome addition. (https://github.com/tideways/php-xhprof-extension)

    • Grav uses Twig rather than Laravel Blade, but I implemented the Twig Profiler into Views via a new Timeline(), however it doesn't actually show a timeline, just the data. I think this is not fully finished as your site doesn't show one either?

    Image 2019-06-05 at 11 13 25 AM

    • UserData field support for objects/arrays similar to the log tab?

    We would also be willing to get our hands dirty and offer up some PRs on this when time permits, but wanted to put these things out there first to see if you are willing to consider them. Cheers!

    Reviewed by rhukster at 2019-06-05 17:23
  • 5. Clockwork Chrome tab empty

    Hi.

    I'm running last versions of clockwork and laravel and the chrome tab is empty (no errors, no queries, nothing)

    However, the log is saving fine.

    What am I missing?

    Thx.

    Reviewed by Luddinus at 2016-05-30 13:14
  • 6. Blank Output in Chrome

    Hello, I installed Clockwork for Chrome and set the provider and alias in Laravel. I extended the Basecontroller too.

    I see in the app/storage/clockwork folder json-files filling up. I read already the other closed issue "blank output". But disabling other profiler don't help me.

    Trying this URL: http://my_host/__clockwork/1385391368.3305.1545016532 I get only a header, but no response:

    Request URL:http://my_host/__clockwork/1385391368.3305.1545016532
    Request Method:GET
    Status Code:200 OK
    Request Headersview source
    Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Accept-Encoding:gzip,deflate,sdch
    Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
    Cache-Control:no-cache
    Connection:keep-alive
    Cookie:laravel_session=eyJpdiI6IlplQ3BVbkd3dDVhcGRzb0xYaW8rWVhuMFFNTFppNFhJcThERHg5VDBZaEk9IiwidmFsdWUiOiJjSUNlZE1Nc3JMR1k2Ykw3d2JSdkpCaUdjYlIwVTBDMk9ubU5LSFdjdDNxMFRCWk1cL3ExWjkzTmVEYStwbGNNMldlYzkxc293NDgzVTFcL3R4Z21qeXNRPT0iLCJtYWMiOiJjOTcwMDFkNTBhOWFhZGQ4NGQzZDI4OWVjNGY3M2E4ZTJkODRmNDYwYWVjNjdmZTE3YTAzMzQxNmJhZWU4ZDMzIn0%3D
    Host:my_host
    Pragma:no-cache
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36
    Response Headersview source
    Connection:Keep-Alive
    Content-Type:text/html
    Date:Fri, 17 Jan 2014 07:56:57 GMT
    Keep-Alive:timeout=5, max=100
    Server:Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/0.9.8y DAV/2 PHP/5.4.4
    Transfer-Encoding:chunked
    X-Powered-By:PHP/5.4.4
    

    Can you help me please? I want to use your tool!

    Reviewed by patrikkernke at 2014-01-17 08:04
  • 7. New User - runtime errors

    Hi,

    Trying out your package (looks good but...) getting some errors. From your console:

    isdb.test/__clockwork/1520887890-8195-1931755551 Failed to load resource: the server responded with a status of 500 (Internal Server Error)

    extensions::messaging:121 Uncaught Error: Message length exceeded maximum allowed length. at PortImpl.postMessage (extensions::messaging:121:13) at Port.publicClassPrototype.(anonymous function) [as postMessage] (extensions::utils:138:26) at responseCallback (extensions::messaging:210:16) at XMLHttpRequest.xhr.onreadystatechange (chrome-extension://dmggabnehkmmfmdffgajcflpdjlnoemp/assets/javascripts/chrome/background.js:29:4)

    Any ideas?

    Thx DJK

    Reviewed by kapsoft at 2018-03-13 13:08
  • 8. Clockwork not parsing file in chrome debugger

    I dont see any output in the Chrome debugger (but the file is definitely created) Do I need to configure a path as to where CW looks for files for parsing?

    http://d.pr/i/iYlP

    Reviewed by mikeerickson at 2015-02-17 21:58
  • 9. Laravel + Clockwork + Chrome not working

    So after many hours of frustration here's where I'm at.

    1. Brand new installation of Laravel 4 (v4.1.21)
    2. Added "itsgoingd/clockwork": "1.*" to my composer.json file.
    3. Ran composer update and Clockwork (v1.4.4) installed.
    4. I added the 'Clockwork\Support\Laravel\ClockworkServiceProvider' to my providers array, and added 'Clockwork' => 'Clockwork\Support\Laravel\Facade', to my aliases array.
    5. I added the following to my app/filters.php file:
    App::before(function($request)
    {
    Event::fire('clockwork.controller.start');
    });
    
    
    App::after(function($request, $response)
    {
    Event::fire('clockwork.controller.end');
    });
    
    1. Ran a composer dump-autoload -o for good measure.
    2. Next I boot up laravel using php artisan serve and we're running on (localhost:8000).
    3. I hit localhost:8000 in chrome, check the headers and here's where things get strange :)

    The headers read:

    X-Clockwork-Id:1392079506.9878.449334262 X-Clockwork-Version:1.4.2

    Note: Composer installed Clockwork v1.4.4 , which is weird?

    This is from my composer.lock file:

        "name": "itsgoingd/clockwork",
            "version": "v1.4.4",
            "source": {
                "type": "git",
                "url": "https://github.com/itsgoingd/clockwork.git",
                "reference": "2d39c88ba507fde4bd21b11971e429762303224c"
            }
    

    I hit the clockwork tab in Chrome (Version 32.0.1700.107) and nothing appears.

    I do at this point have .json' files inapp/storage/clockwork` containing all the correct data that should be being displayed by the Chrome extension.

    A few points where I feel the issue could be laying are:

    1. The use of PHP's built-in web server?
    2. Using SQLite as the database driver of choice?
    3. Chrome on Ubuntu LInux (which I am using).

    I've seen other's mention that white space has been an issue for them, but this isn't the case here. I'll be interested to see if there's a solution to this.

    Reviewed by JasonMortonNZ at 2014-02-11 00:59
  • 10. Not showing SQL values when using ODBC driver

    I'm using Laravel 5.3 with ODBC driver and sqlserver connection but somehow clockwork is not show the values that are passed in the SQL quires.

    I'm attaching screenshot from chrome extension about the current situation.

    You can see both "ticket_user_id" = and "password" = and are blanks ?

    image

    Reviewed by abhimanyu003 at 2017-04-25 14:50
  • 11. Struggling to install under CodeIgniter

    I've attempted to install Clockwork in a fresh copy of CodeIgniter 2.1.4, using Composer, and I'm unable to get it working correctly.

    I've followed the instructions to the letter, but when I load a test controller, I get the message:

    Fatal error: Class 'Clockwork\Support\CodeIgniter\Hook_Clockwork_Register' not found in /application/config/hooks.php 
    

    It's as if Composer isn't loading Clockwork correctly, but I've installed a separate Composer package under the same test site, and this works fine. I am new to Composer, though, so I may have missed an important step; do I have to manually load Clockwork anywhere, or is Composer (and the CodeIgniter hook) designed to do this for me?

    Reviewed by sevenpointsix at 2014-01-31 07:17
  • 12. Web portal __clockwork/latest return false

    Version: 5.16

    When checking via WebPortal /clockwork/app I can see /__clockwork/latest being called but it returns false thus leaving the page blank

    Checking via Chrome Extension it is working as expected

    Reviewed by tokidoki11 at 2022-05-13 07:42
  • 13. Possible update to the documentation re: require-dev

    Re: https://underground.works/clockwork/#docs-installation

    Since this is primarily a development only tool and shouldn't be on production, is there any specific reason why the documentation does not show the default install command for require-dev?

    composer require --dev itsgoingd/clockwork

    Personally I like the better safe than sorry approach. Sometimes a miscommunication with DevOps might have them set the .env variable as true, which can expose a production env. This actually happened with one of ours sites. Luckily I caught it soon enough, but that could have caused major problems if I didn't.

    Another thing I noticed, is that for the same site, the APP_DEBUG was set as false, but CLOCKWORK_ENABLE was set as true. So in this case, setting debug to false was ignored. Perhaps it could be more clearly obvious in the documentation on this page that CLOCKWORK_ENABLE has priority over APP_DEBUG.

    https://underground.works/clockwork/#docs-collected-data

    Reviewed by webdevnerdstuff at 2022-04-18 17:01
  • 14. Use with laravel tinker?

    Is it possible to log the queries when testing with laravel tinker? If so, can you provide instructions on how to enable it? I reviewed the docs and searched the issues, I don't see any other mention of using Tinker.

    Reviewed by freestyledork at 2022-04-07 21:26
  • 15. Improve the readability

    When I read this line I thought that I must visit /app/clockwork and after lots of tries I found out that you mean your_app_url/clockwork So, I think this way is better

    Reviewed by mahmoudmohamedramadan at 2022-04-04 19:38
  • 16. feat: add explanation of queries

    It would be cool if we could explain SQL queries like suggested here: https://github.com/itsgoingd/clockwork/issues/281

    This PR is just a stub to explain how it would work in general. @itsgoingd would you accept a complete PR for this?

    Reviewed by jaulz at 2022-02-25 15:59
The VarDumper component provides mechanisms for walking through any arbitrary PHP variable. It provides a better dump() function that you can use instead of var_dump().

VarDumper Component The VarDumper component provides mechanisms for walking through any arbitrary PHP variable. It provides a better dump() function t

May 18, 2022
Ray server is a beautiful, lightweight php app build on Laravel that helps you debug your app. It runs without installation on multiple platforms.
Ray server is a beautiful, lightweight php app build on Laravel that helps you debug your app. It runs without installation on multiple platforms.

RayServer is a beautiful, lightweight web server built on Laravel and VueJs that helps debugging your app. It runs without installation on multiple platforms.

May 16, 2022
Buggregator is a beautiful, lightweight web server built on Laravel and VueJs that helps debugging your app.
Buggregator is a beautiful, lightweight web server built on Laravel and VueJs that helps debugging your app.

A server for debugging more than just Laravel applications. Buggregator is a beautiful, lightweight web server built on Laravel and VueJs that helps d

May 16, 2022
Php Debugger to run in terminal to debug your code easily.
Php Debugger to run in terminal to debug your code easily.

What is Dephpugger? Dephpugger (read depugger) is an open source lib to make a debug in php direct in terminal, without necessary configure an IDE. Th

Jan 12, 2022
Php Debugger to run in terminal to debug your code easily.
Php Debugger to run in terminal to debug your code easily.

What is Dephpugger? Dephpugger (read depugger) is an open source library that allows a developer to debug in php direct in terminal, without necessary

Jan 12, 2022
Generate Laravel test factories from your existing models

Laravel Test Factory Generator php artisan generate:model-factory This package will generate factories from your existing models so you can get starte

May 15, 2022
Test your routes without hassle
Test your routes without hassle

Laravel Api Tester Live demo Try it out: laravel-api-tester.asva.by Docs Those are short and easy to read. Take a look. Interface FAQ Installation Req

Apr 26, 2022
An artisan command to tail your application logs
An artisan command to tail your application logs

Easily tail your logs This package offers an artisan command to tail the application log. It supports daily and single logs on your local machine. To

May 10, 2022
Handle PHP errors, dump variables, execute PHP code remotely in Google Chrome

PHP Console server library PHP Console allows you to handle PHP errors & exceptions, dump variables, execute PHP code remotely and many other things u

May 19, 2022
PHP APM (Alternative PHP Monitor)

APM (Alternative PHP Monitor) APM (Alternative PHP Monitor) is a monitoring extension enabling native Application Performance Management (APM) for PHP

May 19, 2022
Zipkin PHP is the official PHP Tracer implementation for Zipkin

Zipkin PHP is the official PHP Tracer implementation for Zipkin, supported by the OpenZipkin community. Installation composer require openz

May 14, 2022
Debug bar for PHP
Debug bar for PHP

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 inte

May 11, 2022
Xdebug — Step Debugger and Debugging Aid for PHP

Xdebug Xdebug is a debugging tool for PHP. It provides step-debugging and a whole range of development aids, such as stack traces, a code profiler, fe

May 13, 2022
Kint - a powerful and modern PHP debugging tool.
Kint - a powerful and modern PHP debugging tool.

Kint - debugging helper for PHP developers What am I looking at? At first glance Kint is just a pretty replacement for var_dump(), print_r() and debug

May 14, 2022
😎 Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.
😎 Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.

Tracy - PHP debugger Introduction Tracy library is a useful helper for everyday PHP programmers. It helps you to: quickly detect and correct errors lo

May 20, 2022
PHP Benchmarking framework
PHP Benchmarking framework

PHPBench is a benchmark runner for PHP analogous to PHPUnit but for performance rather than correctness. Features include: Revolutions: Repeat your co

May 22, 2022
The Interactive PHP Debugger

The interactive PHP debugger Implemented as a SAPI module, phpdbg can exert complete control over the environment without impacting the functionality

Apr 26, 2022
Dontbug is a reverse debugger for PHP
Dontbug is a reverse debugger for PHP

Dontbug Debugger Dontbug is a reverse debugger (aka time travel debugger) for PHP. It allows you to record the execution of PHP scripts (in command li

May 8, 2022
PHP Debug Console
PHP Debug Console

PHP Console A web console to try your PHP code into Creating a test file or using php's interactive mode can be a bit cumbersome to try random php sni

May 14, 2022