1. Go to this page and download the library: Download popphp/pop-debug 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/ */
popphp / pop-debug example snippets
use Pop\Debug\Debugger;
use Pop\Debug\Handler\MessageHandler;
use Pop\Debug\Storage\File;
$debugger = new Debugger();
$debugger->addHandler(new MessageHandler());
$debugger->setStorage(new File(__DIR__ . '/log'));
$debugger['message']->addMessage('Hey! Something happened!');
$debugger->save();
use Pop\Debug\Debugger;
use Pop\Debug\Handler\ExceptionHandler;
use Pop\Debug\Storage\File;
$debugger = new Debugger();
$debugger->addHandler(new ExceptionHandler());
$debugger->setStorage(new File(__DIR__ . '/log'));
try {
throw new \Exception('Error: This is a test exception');
} catch (\Exception $e) {
$debugger['exception']->addException($e);
$debugger->save();
}
use Pop\Debug\Debugger;
use Pop\Debug\Handler\MemoryHandler;
use Pop\Debug\Storage\File;
$debugger = new Debugger();
$debugger->addHandler(new MemoryHandler());
$debugger->setStorage(new File(__DIR__ . '/log'));
$debugger['memory']->updateMemoryUsage();
$debugger['memory']->updatePeakMemoryUsage();
sleep(2);
$debugger['memory']->updateMemoryUsage();
$debugger['memory']->updatePeakMemoryUsage();
$debugger->save();
use Pop\Debug\Debugger;
use Pop\Debug\Handler\MessageHandler;
use Pop\Debug\Storage\File;
$debugger = new Debugger();
$debugger->addHandler(new MessageHandler());
$debugger->setStorage(new File(__DIR__ . '/log'));
$debugger['message']->addMessage('Hey! Something happened!');
$debugger->save();
use Pop\Debug\Debugger;
use Pop\Debug\Handler\PhpHandler;
use Pop\Debug\Storage\File;
$debugger = new Debugger();
$debugger->addHandler(new PhpHandler());
$debugger->setStorage(new File(__DIR__ . '/log'));
$debugger->save();
use Pop\Debug\Debugger;
use Pop\Debug\Storage\File;
use Pop\Db\Db;
use Pop\Db\Record;
$db = Db::mysqlConnect([
'database' => 'DATABASE',
'username' => 'DB_USER',
'password' => 'DB_PASS'
]);
class Users extends Record {}
Record::setDb($db);
// Register the query handler with the DB adapter
$queryHandler = $db->listen('Pop\Debug\Handler\QueryHandler');
$debugger = new Debugger();
$debugger->addHandler($queryHandler);
$debugger->setStorage(new File('log'));
// Interact with the database
$user = new Users([
'username' => 'admin',
'password' => 'password'
]);
$user->save();
$debugger->save();
use Pop\Debug\Debugger;
use Pop\Debug\Handler\RequestHandler;
use Pop\Debug\Storage\File;
$debugger = new Debugger();
$debugger->addHandler(new RequestHandler());
$debugger->setStorage(new File(__DIR__ . '/log'));
$debugger->save();
use Pop\Debug\Debugger;
use Pop\Debug\Handler\TimeHandler;
use Pop\Debug\Storage\File;
$debugger = new Debugger();
$debugger->addHandler(new TimeHandler());
$debugger->setStorage(new File(__DIR__ . '/log'));
sleep(2);
$debugger->save();
use Pop\Debug\Debugger;
use Pop\Debug\Handler\TimeHandler;
use Pop\Debug\Storage\File;
$debugger = new Debugger();
$debugger->addHandler(new TimeHandler());
$debugger->setStorage(new File(__DIR__ . '/log'));
use Pop\Debug\Debugger;
use Pop\Debug\Handler\TimeHandler;
use Pop\Debug\Storage\Database;
use Pop\Db\Db;
$db = Db::mysqlConnect([
'database' => 'DATABASE',
'username' => 'DB_USER',
'password' => 'DB_PASS'
]);
$debugger = new Debugger();
$debugger->addHandler(new TimeHandler());
$debugger->setStorage(new Database($db, 'text', 'my_debug_table'));
use Pop\Debug\Storage\File;
$fileStorage = new File(__DIR__ . '/log', 'TEXT');
// OR
$fileStorage = new File(__DIR__ . '/log', 'JSON');
// OR
$fileStorage = new File(__DIR__ . '/log', 'PHP');
use Pop\Debug\Storage\File;
$fileStorage = new File(__DIR__ . '/log');
$fileStorage->setFormat('TEXT');
// OR
$fileStorage->setFormat('JSON');
// OR
$fileStorage->setFormat('PHP');
use Pop\Debug\Debugger;
use Pop\Debug\Handler\MessageHandler;
use Pop\Debug\Storage\File;
$debugger = new Debugger(
new MessageHandler(), new MemoryHandler(), new File(__DIR__ . '/logs')
);
$debugger['message']->addMessage('Hey! Something happened!');
$requestId = $debugger->save();
// A wildcard search
print_r($debugger->getById($requestId . '*'));
// An exact search by ID
print_r($debugger->getById('857f0869d00b64db7c9dbdee4194781a-message'));
print_r($debugger->getByType('message'));
use Pop\Debug\Debugger;
use Pop\Debug\Handler\ExceptionHandler;
use Pop\Debug\Storage\File;
use Pop\Log;
$debugger = new Debugger();
$debugger->addHandler(new ExceptionHandler(true));
$debugger->addLogger(
new Log\Logger(new Log\Writer\File(__DIR__ . '/log/debug.log')),
[
'level' => Log\Logger::ERROR,
'context' => 'json'
]
);
try {
throw new Pop\Debug\Exception('This is a test debug exception');
} catch (\Exception $e) {
$debugger['exception']->addException($e);
$debugger->save();
}
$loggingParams = [
'level' => Log\Logger::WARNING,
'usage_limit' => '500000', // Limit in bytes.
// If the usage goes above the limit,
// the log message is sent
'peak_limit' => '1000000', // Limit in bytes.
// If the peak usage goes above the limit,
// the log message is sent
];
$loggingParams = [
'level' => Log\Logger::WARNING,
'limit' => 1, // Time limit in seconds.
// If the operation takes longer than the time limit,
// the log message is sent
];
use Pop\Debug\Debugger;
use Pop\Db\Db;
use Pop\Db\Record;
use Pop\Db\Adapter\Profiler\Profiler;
use Pop\Log;
$db = Db::mysqlConnect([
'database' => 'DATABASE',
'username' => 'DB_USER',
'password' => 'DB_PASS'
]);
class Users extends Record {}
Record::setDb($db);
// Register the debugger and query handler with the DB adapter
$debugger = new Debugger();
$db->listen('Pop\Debug\Handler\QueryHandler', null, new Profiler($debugger));
// Add logger to the debugger
$debugger->addLogger(
new Log\Logger(new Log\Writer\File(__DIR__ . '/log/debug.log')),
[
'level' => Log\Logger::INFO,
'limit' => 1
]
);
// Save a user to the database - debugging and logging will automatically happen
$user = new Users([
'username' => 'testuser',
'password' => 'password',
'email' => '[email protected]'
]);
$user->save();