PHP code example of 1eonardo-dev / monitoring-client
1. Go to this page and download the library: Download 1eonardo-dev/monitoring-client 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/ */
1eonardo-dev / monitoring-client example snippets
use LeonardoDev\Monitoring\MonitoringClient;
$monitoring = new MonitoringClient(
'https://monitoring.your-company.com',
'mp_...',
'php',
'1.0.0',
);
try {
// your code
} catch (\Throwable $e) {
$monitoring->captureException($e);
}
$monitoring->captureMessage('Something weird happened', 'warning');
use LeonardoDev\Monitoring\Config;
use LeonardoDev\Monitoring\Event;
use LeonardoDev\Monitoring\MonitoringClient;
$client = MonitoringClient::fromConfig(new Config(
'https://monitoring.your-company.com',
'mp_...',
'php',
'1.0.0',
));
$client->captureEvent(new Event('custom', 'warning', 'something happened'));
use LeonardoDev\Monitoring\MonitoringClient;
use LeonardoDev\Monitoring\Transport\Transport;
class GuzzleTransport implements Transport
{
public function send(string $url, string $body, array $headers): ?array
{
// ... return ['status' => int, 'body' => string], or null on failure.
}
}
$client = new MonitoringClient(
'https://monitoring.your-company.com',
'mp_...',
'php',
null,
2,
'/api/v1/events',
new GuzzleTransport(),
);