2017 © Pedro Peláez
 

library profiler

monolog-based profiler

image

foolz/profiler

monolog-based profiler

  • Sunday, February 8, 2015
  • by woxxy
  • Repository
  • 1 Watchers
  • 4 Stars
  • 11,214 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 1 % Grown

The README.md

Foolz\Profiler

This package provides a simple to use profiler, with the power of monolog., (*1)

Requirements

  • PHP 5.4 or higher
  • Monolog (automatically installed with composer)

Installation

Install as any composer package., (*2)

Setup

You should load the profiler early in your code., (*3)

<?php
$profiler = new Profiler();
$profiler->enable();

Until enable isn't run, no request will be logged. You can setup monolog handlers to have custom output options:, (*4)

<?php
$profiler = new Profiler();
$profiler->pushHandler(new ChromePHPHandler());
$profiler->enable();

$profiler->log("Profiler enabled");

HTML output

Remember to check whether you have a text/html request before inserting the HTML profiler panel., (*5)

You can print the current log at any time with $profiler->getHtml()., (*6)

If you use a framework you might have a $response variable that handles the data sent to the client. To put the profiler at the bottom of the page, you may try something similar to the following., (*7)

<?php
$content = explode('</body>', $response->getContent());
if (count($content) == 2) {
    $response->setContent($content[0].$this->profiler->getHtml().$content[1]);
}

$response->send();

Methods

  • pushHandler() As Monolog's pushHandler() function, allows adding log handlers to the logger, (*8)

  • getLogger() Returns the Monolog logger so it can be customized, (*9)

  • enable() Enables the profiler and prints how much time was elapsed since the start of the script, (*10)

  • isEnabled() Tells if the profiler is enabled, (*11)

  • log($string, $context) Logs elapsed time since the beginning of the script and total memory usage The $string variable allows setting a string to identify the entry in the log The $context variable allows adding arbitrary data to the entry, (*12)

  • logMem($string, $variable, $context) Logs memory usage of $variable. While checking, a clone of $variable will be created (it can't be helped), so use with caution. For the rest, it works like log(), (*13)

  • logStart($string, $context) Like log() but it starts a timer, (*14)

  • logStop($string, $context) Like log(), but if called after logStart(), $context will contain elapsed time, (*15)

  • getHtml() Returns an HTML representation of the logged entries, (*16)

The Versions

08/02 2015

dev-master

9999999-dev

monolog-based profiler

  Sources   Download

The Requires

 

by Foolz