PHP code example of stevad / yii2-xhprof

1. Go to this page and download the library: Download stevad/yii2-xhprof library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stevad / yii2-xhprof example snippets


return [
    'bootstrap' => [
        'xhprof'
    ],
    'components' => [
        'xhprof' => [
            'class' => 'stevad\xhprof\XHProfComponent',
            'libPath' => '/full/path/to/xhprof_lib',
            'htmlReportBaseUrl' => 'http://url.to/xhprof_html',
        ],
    ],
];

return [
    'bootstrap' => [
        'debug',
        'xhprof'
    ],
    'components' => [
        'debug' => [
            // ... other debug config options ...
            'panels' => [
                'xhprof' => [
                    'class' => 'stevad\xhprof\XHProfPanel'
                ]
            ]
        ],
    ],
];

// create and configure instance of XHProf class
\stevad\xhprof\XHProf::getInstance()->configure(array(
    'flagNoBuiltins' => true,
    'flagCpu' => false,
    'flagMemory' => true,
    'runNamespace' => 'my-cool-namespace',
    'libPath' => '/var/www/html/xhprof/xhprof_lib',
    'htmlUrlPath' => 'http://test.local/xhprof/xhprof_html'
));

// start profiler
\stevad\xhprof\XHProf::getInstance()->run();

// stop profiler and get URLs to results and callgraph
$urls = \stevad\xhprof\XHProf::getInstance()->stop();

// Links:
// $urls[\stevad\xhprof\XHProf::TYPE_REPORT]
// $urls[\stevad\xhprof\XHProf::TYPE_CALLGRAPH]