2017 © Pedro Peláez
 

library bjy-profiler

Database profiler for Zend\Db (also plugin for ZendDeveloperTools)

image

bjyoungblood/bjy-profiler

Database profiler for Zend\Db (also plugin for ZendDeveloperTools)

  • Thursday, September 4, 2014
  • by bjyoungblood
  • Repository
  • 15 Watchers
  • 84 Stars
  • 258,307 Installations
  • PHP
  • 11 Dependents
  • 2 Suggesters
  • 54 Forks
  • 16 Open issues
  • 3 Versions
  • 4 % Grown

The README.md

BjyProfiler

Provides Zend\Db adapters with extensions for database query profiling, as well as a profiler similar to ZF1's Zend_Db_Profiler. I ported much of this code from ZF1's Zend_Db., (*1)

Note: this module now works with Zend\Db's built-in profiler., (*2)

Note: PHP >= 5.3.6 is required for stack traces with query profiles., (*3)

Composer/Packagist Users

Please note the name of this project's package has changed to bjyoungblood/bjy-profiler in order to match composer/packagist's new naming conventions. Please update your composer.json to use the new package name., (*4)

Configuration & Usage

Following is a sample database configuration:, (*5)

<?php

$dbParams = array(
    'database'  => 'changeme',
    'username'  => 'changeme',
    'password'  => 'changeme',
    'hostname'  => 'localhost',
    // buffer_results - only for mysqli buffered queries, skip for others
    'options' => array('buffer_results' => true)
);

return array(
    'service_manager' => array(
        'factories' => array(
            'Zend\Db\Adapter\Adapter' => function ($sm) use ($dbParams) {
                $adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter(array(
                    'driver'    => 'pdo',
                    'dsn'       => 'mysql:dbname='.$dbParams['database'].';host='.$dbParams['hostname'],
                    'database'  => $dbParams['database'],
                    'username'  => $dbParams['username'],
                    'password'  => $dbParams['password'],
                    'hostname'  => $dbParams['hostname'],
                ));

                if (php_sapi_name() == 'cli') {
                    $logger = new Zend\Log\Logger();
                    // write queries profiling info to stdout in CLI mode
                    $writer = new Zend\Log\Writer\Stream('php://output');
                    $logger->addWriter($writer, Zend\Log\Logger::DEBUG);
                    $adapter->setProfiler(new BjyProfiler\Db\Profiler\LoggingProfiler($logger));
                } else {
                    $adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler());
                }
                if (isset($dbParams['options']) && is_array($dbParams['options'])) {
                    $options = $dbParams['options'];
                } else {
                    $options = array();
                }
                $adapter->injectProfilingStatementPrototype($options);
                return $adapter;
            },
        ),
    ),
);

After you've run a couple queries (or before, if you so choose), you can use the service locator to grab the adapter using whatever alias you provide (using Zend\Db\Adapter\Adapter is a good way to simply replace Zend\Db's adapter with my profiling adapter., (*6)

$profiler = $sl->get('Zend\Db\Adapter\Adapter')->getProfiler();
$queryProfiles = $profiler->getQueryProfiles();

The Versions

04/09 2014

dev-master

9999999-dev https://github.com/bjyoungblood/BjyProfiler

Database profiler for Zend\Db (also plugin for ZendDeveloperTools)

  Sources   Download

MIT

The Requires

 

zf2 db profiler zdt

11/03 2014

v1.1.0

1.1.0.0 https://github.com/bjyoungblood/BjyProfiler

Database profiler for Zend\Db (also plugin for ZendDeveloperTools)

  Sources   Download

The Requires

 

zf2 db profiler zdt

25/07 2013

v1.0.0

1.0.0.0 https://github.com/bjyoungblood/BjyProfiler

Database profiler for Zend\Db (also plugin for ZendDeveloperTools)

  Sources   Download

The Requires

 

zf2 db profiler zdt