PHP code example of perfbase / cakephp

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

    

perfbase / cakephp example snippets


use Cake\Http\BaseApplication;
use Perfbase\CakePHP\PerfbasePlugin;

class Application extends BaseApplication
{
    public function bootstrap(): void
    {
        parent::bootstrap();

        $this->addPlugin(PerfbasePlugin::class);
    }
}



use Perfbase\SDK\FeatureFlags;

return [
    'Perfbase' => [
        'enabled' => true,
        'api_key' => env('PERFBASE_API_KEY'),
        'sample_rate' => 0.1,
        'profile_http_status_codes' => [...range(200, 299), ...range(500, 599)],
        'flags' => FeatureFlags::DefaultFlags,
        'environment' => env('APP_ENV', 'production'),
        'app_version' => env('APP_VERSION', ''),
    ],
];

return [
    'Perfbase' => [
        'enabled' => false,
        'debug' => false,
        'log_errors' => true,
        'api_key' => null,
        'api_url' => 'https://ingress.perfbase.cloud',
        'sample_rate' => 0.1,
        'profile_http_status_codes' => [...range(200, 299), ...range(500, 599)],
        'timeout' => 10,
        'proxy' => null,
        'flags' => \Perfbase\SDK\FeatureFlags::DefaultFlags,
        'environment' => 'production',
        'app_version' => '',
        '

use Cake\Core\Configure;

Configure::write('Perfbase', [
    'enabled' => true,
    'api_key' => env('PERFBASE_API_KEY'),
    'sample_rate' => 1.0,
]);

use Perfbase\SDK\FeatureFlags;

'flags' => FeatureFlags::DefaultFlags;
'flags' => FeatureFlags::AllFlags;
'flags' => FeatureFlags::TrackCpuTime | FeatureFlags::TrackPdo;

return [
    'Perfbase' => [
        ', 'POST /checkout'],
            'console' => ['migrations:*', 'cache clear*'],
        ],
        'exclude' => [
            'http' => ['GET /health*', '/metrics'],
            'console' => ['debug:*'],
        ],
    ],
];

namespace App\Command;

use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Perfbase\CakePHP\Command\ProfiledCommand;

class ExampleCommand extends ProfiledCommand
{
    public function execute(Arguments $args, ConsoleIo $io)
    {
        $io->out('Perfbase command profiling is active.');

        return static::CODE_SUCCESS;
    }
}



use Perfbase\SDK\FeatureFlags;

return [
    'Perfbase' => [
        'enabled' => true,
        'api_key' => env('PERFBASE_API_KEY'),
        'sample_rate' => 0.02,
        'timeout' => 5,
        'flags' => FeatureFlags::UseCoarseClock | FeatureFlags::TrackCpuTime | FeatureFlags::TrackPdo,
        'environment' => env('APP_ENV', 'production'),
        'app_version' => env('APP_VERSION', ''),
        'exclude' => [
            'http' => ['GET /health*', '/metrics'],
        ],
    ],
];
bash
export PERFBASE_API_KEY=your-api-key-here
bash
php -m | grep perfbase
php --ini