PHP code example of vitorsreis / extend-analysis

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

    

vitorsreis / extend-analysis example snippets


use VSR\Extend\Analysis;

# Create driver
$driver = new Analysis\Driver\Standard(__DIR__);

# Set driver
Analysis::setDriver($driver);

# @param bool $autoSave [optional] Save automatically on shutdown event
#                       default: true, if false, you need call $requestProfile->save() manually
global $profile;
$profile = new Analysis\Request();

global $profile;
try {
    $profile->start(/* profile_name */); # up level, start action monitor
    // your code
} catch (Throwable $e) {
    $profile->error($e); # register error in current level
    // your code
} finally {
    $extra = ...; // [optional] extra info about action
    $profile->stop($extra || null); # down level, end action monitor
}

$requestProfile->extra(...);

global $requestProfile;
$requestProfile->onBeforeSave(function (array $request) {
    # Toleration of 1000 actions, 300ms of duration and not error
    if ($request['profile_count'] < 1000 && $request['duration'] < .300 && !$request['error']) {
        # Remove debug fields to save space in database
        $fields = [
            'referer',
            'useragent',
            'get',
            'post',
            'raw_post',
            'files',
            'cookies',
            'server',
            'headers', 
            'inc_files',
            'error',
            'extra',
            'profile'
        ];
        foreach ($fields as $field) {
            $request[$field] = null;
        }
    }
    return $request;
});