Welcome to Abdul Malik Ikhsan's Blog

Zend Framework 2 : ZendDeveloperTools : The ZF2 tools You must install

Posted in Teknologi, Tutorial PHP, Zend Framework 2 by samsonasik on August 7, 2012

ZendDeveloperTools is a Module for developer and debug tools for working with the ZF2 MVC layer. It can show you a request method, response code, current controller/action, current route we access, execution time, memory consumption, grab the profiler of Zend\Db adapter instance, and Zend Framework version you currently use.


The success installed :

ZendDeveloperTools Module installation :
1. Clone ZendDeveloperTools from Github

git clone git://github.com/zendframework/ZendDeveloperTools.git

2. Copy to vendor folder
3. Copy `ZendDeveloperTools/config/zenddevelopertools.local.php.dist` to
`./config/autoload/zenddevelopertools.local.php`. Change the settings
if you like to.
4. Add the following in your `index.php` first line :

define('REQUEST_MICROTIME', microtime(true));

5. Enable it in application.config.php

<?php
return array(
    'modules' => array(
        'Application',
        'ZendDeveloperTools',
    ),
    'module_listener_options' => array(
        'config_glob_paths'    => array(
            'config/autoload/{,*.}{global,local}.php',
        ),
        'module_paths' => array(
            './module',
            './vendor',
        ),
    ),
);

If you wish to profile Zend\Db, you have to install and enable [BjyProfiler] :
1. Clone BjyProfiler Module from Github/

git clone git://github.com/bjyoungblood/BjyProfiler.git

2. Copy to vendor folder
3. Change your database configuration like the following :

$dbParams = array(
    'database'  => 'zf2',
    'username'  => 'developer',
    'password'  => '123456',
    'hostname'  => 'localhost'
);

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'       => 'pgsql:dbname='.$dbParams['database'].';host='.$dbParams['hostname'],
                    'database'  => $dbParams['database'],
                    'username'  => $dbParams['username'],
                    'password'  => $dbParams['password'],
                    'hostname'  => $dbParams['hostname'],
                ));

                $adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler);
                $adapter->injectProfilingStatementPrototype();
                return $adapter;
            },
        ),
    ),
);

4. Enable it in application.config.php

<?php
return array(
    'modules' => array(
        'Application',
        'ZendDeveloperTools',
        'BjyProfiler'
   ),
    'module_listener_options' => array(
        'config_glob_paths'    => array(
            'config/autoload/{,*.}{global,local}.php',
        ),
        'module_paths' => array(
            './module',
            './vendor',
        ),
    ),
);

If your installation succeded, you can debug your application :

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

foreach($queryProfiles as $key=>$row)
{
    print_r($row->toArray());
}

And the result will like this :

References :
1. https://github.com/zendframework/ZendDeveloperTools/blob/master/README.md
2. https://github.com/bjyoungblood/BjyProfiler/blob/master/README.md

Advertisements

47 Responses

Subscribe to comments with RSS.

  1. Michaël Gallego said, on September 23, 2012 at 2:17 am

    Note that profiling through Zend Developer Tools is also available for Doctrine with DoctrineORMModule (the official ZF 2 Doctrine module ;-).

  2. samsonasik said, on September 23, 2012 at 5:17 am

    thanks 😉

  3. Dragos said, on November 10, 2012 at 11:13 am

    How can achieve this with zend 2 for doctrine2?

  4. samsonasik said, on November 10, 2012 at 11:16 pm

    install DoctrineORMModule : https://github.com/doctrine/DoctrineORMModule

  5. Dragos said, on November 11, 2012 at 11:36 pm

    I installed already, but i don’t know how to show profiler informations in zend 2

  6. samsonasik said, on November 12, 2012 at 11:51 am

    configure your composer.json :

    {
        "name": "zendframework/skeleton-application",
        "description": "Skeleton Application for ZF2",
        "license": "BSD-3-Clause",
        "keywords": [
            "framework",
            "zf2"
        ],
        "homepage": "http://framework.zend.com/",
        "minimum-stability": "alpha",
        "require": {
            "php": ">=5.3.3",
            "zendframework/zendframework": "2.*",
            "doctrine/migrations" : "dev-master",
            "doctrine/doctrine-orm-module": "0.*"
        }
    }
    

    and run,

    COMPOSER_PROCESS_TIMEOUT=5000 php composer.phar install
    

    Follow https://github.com/doctrine/DoctrineORMModule/blob/master/README.md configuration.

    Last but not least, register at application.config.php

    return array(
        'modules' => array(
            'Application',
            'DoctrineModule',
            'DoctrineORMModule',
            'ZendDeveloperTools'
        ),
        'module_listener_options' => array(
            'config_glob_paths'    => array(
                'config/autoload/{,*.}{global,local}.php',
            ),
            'module_paths' => array(
                './module',
                './vendor',
            ),
        ),
    );
    
  7. Dragos said, on November 12, 2012 at 8:27 pm

    Tank you Malik for take time to responde me but how i said i already install doctrine module, installed on: vendor/doctrine/doctrine-orm-module. I google it more and i find what to do, I write here maybe would help someone else who just started with zend 2. So all i have to do is put in root config autoload this:
    return array(
    ‘zenddevelopertools’ => array(
    ‘profiler’ => array(
    ‘enabled’ => true,
    ‘strict’ => true,
    ‘verbose’ => true,
    ‘flush_early’ => false,
    ‘cache_dir’ => ‘data/cache’,
    ‘collectors’ => array(),
    ‘verbose_listeners’ => array(‘application’ => array(
    ‘ZDT_TimeCollectorListener’ => true,
    ‘ZDT_MemoryCollectorListener’ => true,
    ))
    ),
    ‘toolbar’ => array(
    ‘enabled’ => true,
    ‘auto_hide’ => false,
    ‘position’ => ‘bottom’,
    ‘version_check’ => false,
    ‘entries’ => array(),
    ),
    ),
    );

  8. sumbersoft said, on November 14, 2012 at 1:42 pm

    q udah ikutin langkah2 nya tapi ga jalan, trus q coba copy ZendDeveloperTools ke folder module baru jalan gan. kok bisa ya

    • samsonasik said, on November 14, 2012 at 4:07 pm

      berarti di application.config.php kamu cuma ada folder module, tambahkan jg folder vendor. kalau ga jalan, update zf2 terbaru.

  9. aldo praherda said, on November 14, 2012 at 1:54 pm

    gan langkah 3. Change your database configuration like the following : itu file apa yg diedit? aq pake doctrine

  10. Piotr Stępniewski said, on December 9, 2012 at 8:37 pm

    Hi!
    You can move all DB config parameters to /config/autoload/local.php:

    return array(
    ‘db’ => array(
    ‘username’ => ‘user1234’,
    ‘password’ => ‘passABCD’,
    ‘driver’ => ‘Pdo’,
    ‘dsn’ => ‘mysql:dbname=db_name;host=localhost’,
    ‘driver_options’ => array(
    PDO::MYSQL_ATTR_INIT_COMMAND => ‘SET NAMES \’UTF8\”
    ),
    ),
    );

    In global.php we can leave only insensitive data (db name, password, login, etc):

    […]
    ‘Zend\Db\Adapter\Adapter’ => function ($sm) {
    $config = $sm->get(“config”);
    $adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter($config[‘db’]);
    $adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler);
    $adapter->injectProfilingStatementPrototype();
    return $adapter;
    },
    […]

    Now configuration file is more friendly. 😉
    Best regards!
    Piotr

  11. Webdevilopers said, on February 5, 2013 at 3:21 pm

    Denis Ryabov has posted a nice solution to view queries inside the toolbar template:
    http://stackoverflow.com/questions/13275569/how-to-view-db-queries-generated-by-tablegateway-in-zend-framework-2

    It would be nice to see this feature inside the BjyProfiler container.

  12. […] Zend Developer Tools GIT tutorial […]

  13. Bineet chaubey said, on June 4, 2013 at 4:49 pm

    hi i have install zenddevelopertools modules with bjyoungblood/BjyProfiler module but still showing

    https://a248.e.akamai.net/camo.github.com/94e40145f871bc995499a793a19dc7a82950747c/687474703a2f2f692e696d6775722e636f6d2f414f6a65422e706e67

    i have configure all thing according to zenddevelopertools guide and you say in this post but still get above image result

    Please help me ..

    Thanks

    • samsonasik said, on June 4, 2013 at 5:07 pm

      check BjyProfiler guide too, and don’t forget to add to the config/application.config.php

      • Bineet chaubey said, on June 4, 2013 at 6:20 pm

        i did this but no effect , my config/application.config.php content is

        array(
        ‘ZendDeveloperTools’,
        ‘DoctrineModule’,
        ‘DoctrineORMModule’,
        ‘BjyProfiler’,
        ‘Application’,
        ‘Blog’,
        ‘Incuser’,
        // ‘Myacl’,
        //’ZfcBase’,
        //’ZfcUser’
        ),
        ‘module_listener_options’ => array(
        ‘config_glob_paths’ => array(
        ‘config/autoload/{,*.}{global,local}.php’,
        ),
        ‘module_paths’ => array(
        ‘./module’,
        ‘./vendor’,
        ),
        ),
        );

  14. bw said, on August 11, 2013 at 2:50 am

    Same Problem….

  15. Ragunathan K said, on August 30, 2013 at 1:58 am

    I Want to write my own sql script in my controller in my index action..tell how to write the query and how to fetch the data in index phtml file

  16. Mr Andrew said, on October 13, 2013 at 5:03 pm

    Can you write a tutorial about mongodb and zend framework 2 plz, I always got error AnnominationsRegistertry not found in DoctrineModule/Module . Thank you.

  17. Marc said, on December 2, 2013 at 9:09 am

    Abdul, thank you for all your usefull posts!

    I have a question about the meaning of the drawer icon. Does it represent de total load of the page?
    When I load my page de developer-tool-bar it says 7.75 Mb (= 992 KB) but if I check my firefox console it says 321.73 KB.

    How should I understand it? Thank you

    • samsonasik said, on December 2, 2013 at 9:51 am

      I think firefox console only check memory to load asset (html/js/css), and the zenddevelopertools check memory to consume asset , php & database execution 🙂

  18. angeledugo said, on January 29, 2014 at 3:47 am

    BjyProfiler multiple Db help me ….

  19. Ahammad karim said, on June 4, 2014 at 1:36 pm

    where to put this code
    $profiler = $this->getServiceLocator()->get(‘Zend\Db\Adapter\Adapter’)->getProfiler();
    $queryProfiles = $profiler->getQueryProfiles();

    foreach($queryProfiles as $key=>$row)
    {
    print_r($row->toArray());
    }

    I am not clear. Please help me

    • BehRang said, on July 24, 2014 at 10:37 pm

      I have the same problem !

  20. may saghira said, on September 18, 2014 at 8:18 pm

    thanks Samsonasik for the tuto i’ve followed the tuto but i’ve get a problem , i have an application working with zend franmework 2 and doctrine.when i added zendDevelopperTools i can’t log in , the application stoped working.

  21. may saghira said, on September 18, 2014 at 11:27 pm

    problem fixed , just edit the zenddevelopertools.local.php just like mentionned here :
    http://stackoverflow.com/questions/11519800/zenddevelopertools-module-not-displaying-a-toolbar-in-zf2-beta5

  22. Akbar Adeeb said, on July 6, 2015 at 4:01 pm

    Thanks for your post
    Can you please tell me how i remove it when going to online

    • samsonasik said, on July 7, 2015 at 2:41 am

      set application environments, for ex: ‘development’, ‘production’, ‘test’, etc. so, when you change the environment you can enable/disable modules you need.

  23. wiktoratgmail said, on July 17, 2015 at 7:32 pm

    At first try I’ve downloaded it from github by: git clone

    and get error:

    Fatal error: Uncaught exception ‘Zend\ModuleManager\Exception\RuntimeException’ with message ‘Module (ZendDeveloperTools) could not be initialized.’

    At second try I’ve used composer:

    composer require zendframework/zend-developer-tools:dev-master

    and it works like a charm 🙂

    • samsonasik said, on July 21, 2015 at 3:45 pm

      current ZendDeveloperTools now rely on composer for autoloading, that’s why it works with composer.

  24. Mongo said, on April 4, 2016 at 5:55 pm

    Please give some examples for Zend2+MongoDB+Doctrine2

  25. Abdoulaye said, on December 15, 2016 at 9:28 pm

    That’s a useful tool. It helps me.
    Thanks a lot.

  26. David said, on March 16, 2017 at 3:22 am

    How would you configure for multiple database?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: