PHP code example of zachete / profiler

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

    

zachete / profiler example snippets




use Zachete\Profiler;

$profiler = new Profiler();

$profiler->label('Sleep for 1 second');
sleep(1);

$profiler->label('Sleep for 2 seconds');
sleep(3);

$profiler->get('Sleep for 1 seconds'); // return ~ 4.004
$profiler->get('Sleep for 2 seconds'); // return ~ 3.002

public function register() {
    $this->app->instance('Zachete\Profiler', new Profiler([
        'logging_function' => function($labelName, $value) {
            info("Profile {$labelName} with {$value} seconds");
        }
    ]));
}

// some method
public function someMethod(Profiler $profiler) {
    $profiler->label('some label');

    sleep(4);

    // The code below will also log result
    // using info() method with a provided string
    // ("Profile some label with 4.004 seconds")

    $profiler->get('some label');
}