1. Go to this page and download the library: Download monitaroo/monitaroo-php 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/ */
monitaroo / monitaroo-php example snippets
use Monitaroo\Monitaroo;
// Initialize once (e.g., in bootstrap)
Monitaroo::init([
'apiKey' => 'mk_your_api_key',
'service' => 'my-app',
'environment' => 'production',
]);
// Log messages (buffered, auto-flushed at end of request)
Monitaroo::info('User logged in', ['user_id' => 123]);
Monitaroo::error('Payment failed', ['order_id' => 456, 'tags' => ['type' => 'payment']]);
// Record metrics
Monitaroo::increment('orders.completed');
Monitaroo::gauge('queue.size', 42);
Monitaroo::timing('api.response_time', 145.5);
// Timer helper
$stop = Monitaroo::startTimer('db.query');
$result = $db->query('SELECT ...');
$elapsed = $stop(); // Automatically records the metric
Monitaroo::init([
// Required
'apiKey' => 'mk_xxx', // Your API key from Monitaroo dashboard
// Optional - Default context for all logs
'service' => 'my-app', // Service name
'environment' => 'production', // Environment (production, staging, dev)
'host' => 'server-01', // Host name (auto-detected if not set)
// Optional - Performance tuning
'endpoint' => 'https://api.monitaroo.com', // API endpoint
'batchSize' => 100, // Flush after N items (default: 100)
'autoFlush' => true, // Auto-flush on shutdown (default: true)
]);
use Monitaroo\Monitaroo;
// Get PSR-3 compatible logger
$logger = Monitaroo::logger();
// Use with any PSR-3 compatible library
$logger->info('Hello {name}', ['name' => 'World']);
// Simple increment
Monitaroo::increment('api.requests');
// Increment by value
Monitaroo::increment('items.sold', 5);
// With tags
Monitaroo::increment('api.requests', 1, [
'endpoint' => '/users',
'method' => 'GET',
]);
Monitaroo::init([
'apiKey' => 'mk_xxx',
'autoFlush' => false, // Manual flush only
]);
// Must call flush manually
Monitaroo::flush();
use Monitaroo\Client;
use Monitaroo\Transport\TransportInterface;
class MyTransport implements TransportInterface
{
public function sendLogs(array $logs): void
{
// Custom implementation
}
public function sendMetrics(array $metrics): void
{
// Custom implementation
}
}
$client = new Client([
'apiKey' => 'mk_xxx',
'transport' => new MyTransport(),
]);
use Monitaroo\Client;
$clientA = new Client(['apiKey' => 'mk_app_a', 'service' => 'app-a']);
$clientB = new Client(['apiKey' => 'mk_app_b', 'service' => 'app-b']);
$clientA->info('From app A');
$clientB->info('From app B');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.