PHP code example of petrknap / php-profiler

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

    

petrknap / php-profiler example snippets




use PetrKnap\Php\Profiler\Profile;
use PetrKnap\Php\Profiler\SimpleProfiler;

SimpleProfiler::enable();
Profile::setProfiler(SimpleProfiler::class);

Profile::start();
/* your code goes here */
var_dump(Profile::finish());



use PetrKnap\Php\Profiler\Profile;

Profile::start(/* sprintf( */ "static label" /* ) */);
Profile::start(/* sprintf( */ "line %s", __LINE__ /* ) */);



use PetrKnap\Php\Profiler\Profile;

Profile::start("Profile 1");
    /* your code goes here */
    Profile::start("Profile 1.1");
        Profile::start("Profile 1.1.1");
            /* your code goes here */
        Profile::finish("Profile 1.1.1");
        /* your code goes here */
        Profile::start("Profile 1.1.2");
            /* your code goes here */
        Profile::finish("Profile 1.1.2");
        /* your code goes here */
    Profile::finish("Profile 1.1");
Profile::finish("Profile 1");



use PetrKnap\Php\Profiler\SimpleProfiler;

SimpleProfiler::enable();

SimpleProfiler::start();
/* your code goes here */
var_dump(SimpleProfiler::finish());



use PetrKnap\Php\Profiler\AdvancedProfiler;
use PetrKnap\Php\Profiler\Profile;

AdvancedProfiler::setPostProcessor(function(Profile $profile) {
    var_dump($profile);
});
AdvancedProfiler::enable();

AdvancedProfiler::start();
/* your code goes here */
AdvancedProfiler::finish();
json
{
    "etrknap/php-profiler": "dev-master"
    }
}