PHP code example of yiisoft / profiler

1. Go to this page and download the library: Download yiisoft/profiler 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/ */

    

yiisoft / profiler example snippets


return [
    //...
    'yiisoft/aliases' => [
        'aliases' => [
            //...
            '@runtime' => '@root/runtime'
        ],
    ],
    //...
];

use Psr\Log\NullLogger;
use Yiisoft\Profiler\Profiler;
use Yiisoft\Profiler\Target\LogTarget;

$logger = new NullLogger();
$target = new LogTarget($logger);

$profiler = new Profiler($logger, [$target]);

$profiler->begin('test');
//...some code
$profiler->end('test');


$profiler->begin('test');
//...some code
    $profiler->begin('test');
    //...some code
    $profiler->end('test');
//...some code
$profiler->end('test');

$messages = $profiler->getMessages(); 
print_r($messages);

$profiler->begin('test');
//...some code
$profiler->end('test');
$profiler->begin('another test');
//...some code
$profiler->end('another test');

$messages = $profiler->findMessages('another test');
print_r($messages);

// obtain profiler
$profiler = getProfiler();
// send profiler messages to targets
$profiler->flush();