2017 © Pedro Peláez
 

library debug

Simple debugging utility for PHP.

image

zidizei/debug

Simple debugging utility for PHP.

  • Sunday, February 7, 2016
  • by zidizei
  • Repository
  • 4 Watchers
  • 8 Stars
  • 10,168 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

debug-php

Simple debugging utility for PHP to print out messages to stdout or the browser's JavaScript console, if supported., (*1)

Heavily inspired by debug for node.js., (*2)

Latest Stable Version Total Downloads License, (*3)

Installation

Use Composer and add this to your composer.json:, (*4)

"require": {
    "zidizei/debug", "~0.1.1"
}

Usage

debug-php lets you print out short debbuging messages for your PHP project either to stdout or to the JavaScript console of your browser, in case you are using this library on your website., (*5)

require "vendor/autoload.php";

// initiate debug profile named 'parser'
\Debug\profile("parser");

\Debug\debug("Parsing some stuff now");
/* Parse the stuff */
\Debug\debug("Stuff successfully parsed");

// close the current debug profile (in this case 'parser')
\Debug\profile();

The above code will produce something like this when run using a web server and browser:, (*6)

parser debug, (*7)

Output to stdout will look more or less the same using colors defined by your shell., (*8)

Disabling debugging messages

By default, debug-php is good to go by just calling its methods. Since 0.1.1 you can call \Debug\off() to explicitly disable debugging messages. In combination with \Debug\on(), this could be used to programmatically decide to skip debug messages for certain sections of your code., (*9)

Multiple Profiles

You can use profiles to better distinguish some of your debug messages. The example above only uses one profile by calling:, (*10)

\Debug\profile("parser")

If a profile by that name already exists, it will be closed. You can close the currently active (as in last opened) profile by omitting the parameter:, (*11)

\Debug\profile()

If there are no active profiles, it will open a default one (aptly named default). Note that there has to be at least one profile open for debugging., (*12)

The following code example demonstrates the use of multiple debugging profiles:, (*13)

require "../vendor/autoload.php";

// initiate debug profile named 'parser'
\Debug\profile("parser");

\Debug\debug("Parsing some stuff now");
/* Parse the stuff */
\Debug\debug("Stuff successfully parsed");


// initiate debug profile named 'worker'
\Debug\profile("worker");

\Debug\debug("Working with the stuff now");
/* Work with the parsed stuff */
\Debug\debug("Stuff successfully worked with.. or something like that.");

// close the current debug profile (in this case 'worker')
\Debug\profile();


// close the current debug profile (in this case 'parser')
\Debug\profile();

The above code will produce something like this when run using a web server and browser:, (*14)

multiple profiles debug, (*15)

Output to stdout will look more or less the same using colors defined by your shell., (*16)

Time measurements

The milliseconds at the end of each debug line indicate the time difference between the execution of the current debug message and the previous one., (*17)

Additionally, each profile duration is measured and displayed once it has been closed., (*18)

The Versions

07/02 2016

dev-master

9999999-dev http://patrickl.am/debug-php

Simple debugging utility for PHP.

  Sources   Download

MIT

The Requires

  • php >=4.3.0

 

by Patrick Lam

debug console javascript

14/02 2015

0.1.1

0.1.1.0 http://github.com/zidizei/debug-php

Simple debugging utility for PHP.

  Sources   Download

MIT

The Requires

  • php >=4.3.0

 

by Patrick Lam

debug console javascript

28/03 2014

0.1.0

0.1.0.0 http://github.com/zidizei/debug-php

Simple debugging utility for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Patrick Lam

debug console javascript