t4web/profiler

ZF2 Module. Allow profiling and log slow request

0.1.0 2016-07-29 13:52 UTC

This package is auto-updated.

Last update: 2024-10-26 18:01:22 UTC


README

ZF2 Module. Allow profiling and log slow request

Contents

Introduction

Module for allow profiling page load speed. You can add custom timers for detail analyze page loading workflow.

Installation

Main Setup

By cloning project

Clone this project into your ./vendor/ directory.

With composer

Add this project in your composer.json:

"require": {
    "t4web/profiler": "~0.1.0"
}

Now tell composer to download T4web\Profiler by running the command:

$ php composer.phar update

Post installation

Enabling it in your application.config.phpfile.

<?php
return array(
    'modules' => array(
        // ...
        'T4web\DefaultService',
        'T4web\Profiler',
    ),
    // ...
);

T4web\Profiler require T4web\DefaultService module.

Configuring

By default profiles not store (using NullAdapter), for storing page profiles into your DB, you can use DbAdapter. Run init script for create profiler table:

$ php public/index.php profiler init

Change default StorageAdapter:

'service_manager' => [
    'factories' => [
        \T4web\Profiler\StorageAdapter\StorageAdapterInterface::class => \T4web\Profiler\StorageAdapter\DbAdapterFactory::class,
    ],
],

Or, you can implement T4web\Profiler\StorageAdapter\StorageAdapterInterface for create own profiler storage.

By default profiler calculate basic ZF2 event execution:

{
    "route": "1ms",
    "dispatch": "12ms",
    "render": "0ms",
    "finish": "0ms"
}

you can disable this like this:

't4web-profiler' => [
    'profiling-timeout' => 500, // in ms
    'use-default-listeners' => false,
],

Profiler store request, which execute more than profiling-timeout option (500ms by default).

Timers

You can add any custom timers. Timer - it's name and execution time.

$profiler = $serviceLocator->get(T4web\Profiler\Profiler::class);
$profiler->startTimer('My slow function');
// ...
$profiler->endTimer('My slow function');