PHP code example of particletree / pqp

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

    

particletree / pqp example snippets




$console = new Particletree\Pqp\Console();
$profiler = new Particletree\Pqp\PhpQuickProfiler();
$profiler->setConsole($console);

// let the application do its thing
$console->log('Hello World');
$console->logSpeed();

// after the app shutdown - will spew out HTML
$profiler->display();

$console = new Particletree\Pqp\Console();
$console->log('A String');

$array = array('a value');
$console->log($array);

$console = new Particletree\Pqp\Console();
$console->logMemory();

$date = new Datetime('+5 days');
$console->logMemory($date, 'five days from now');

$console = new Particletree\Pqp\Console();
try {
  // bad code
} catch (Exception $e) {
  $console->logError($e);
}

$console = new Particletree\Pqp\Console();
$console->logSpeed('right now');
// some code
$console->logSpeed('a bit later');

$profiler = new Particletree\Pqp\PhpQuickProfiler();

$profiledQueries = [
  [
    'sql' => 'SELECT * FROM posts WHERE active = :active',
    'parameters' => ['active' => 1],
    'time' => 5,
  ],
  [
    'sql' => 'UPDATE posts SET active = :active WHERE id = :id',
    'parameters' => ['active' => 1, 'id' => 5],
    'time' => 1,
  ],
];

$profiler->setProfiledQueries($profiledQueries);

$profiledQueries = $pdo->getProfiler()->getProfiles();
$profiledQueries = array_filter($profiledQueries, function ($profile) {
  return $profile['function'] == 'perform';
});
$profiledQueries = array_map(function ($profile) {
  return array(
    'sql' => trim(preg_replace('/\s+/', ' ', $profile['statement'])),
    'parameters' => $profile['bind_values'],
    'time' => $profile['duration']
  );
}, $profiledQueries);