PHP
Library for PHP Applications
What it is for
The official DockRay PHP SDK lets you integrate any PHP application with the DockRay monitoring platform. It automatically reports unhandled exceptions and PHP errors and enables HTTP request performance monitoring.
PHP Error and Exception Monitoring
DockRay can automatically capture unhandled exceptions and fatal PHP errors and send them to the monitoring dashboard.
Reported events can include:
- the error or exception type and message,
- where it occurred and the stack trace,
- environment and application version information,
- tags, user data, and additional context.
The SDK also allows you to manually report exceptions and messages and add your own diagnostic information using tags, user data, and breadcrumbs.
Performance Monitoring
The SDK enables HTTP transaction and request processing time monitoring. The frequency of data collection can be controlled using a sampling rate.
JavaScript Error Monitoring
The DockRay PHP SDK also provides tools for integrating JavaScript error monitoring. Browser events are forwarded through your PHP application, keeping the project's private key securely on the server.
Built for Production Applications
By default, events are queued while the request is being processed and sent after the response has been prepared. This means a temporarily unavailable or slower monitoring service should not delay the application response for the user.
Framework-Agnostic
The DockRay PHP SDK does not require a specific framework and can be used with any PHP 8.2+ application. It also serves as the foundation for dedicated DockRay integrations for popular frameworks and CMS platforms.
Installation
Install the DockRay PHP SDK using Composer:
composer require dockcodes/dock-ray
The package requires PHP 8.2 or later.
Configuration
Initialize DockRay when your application starts, providing your project token and private key:
use function Dock\Ray\init;
init([
'token' => 'PROJECT_TOKEN',
'private_key' => 'PROJECT_PRIVATE_KEY',
'environment' => 'production',
'release' => '1.4.0',
]);
You can find your project token and private key in the DockRay dashboard. The credentials can also be provided using the RAY_TOKEN and RAY_PRIVATE_KEY server environment variables.
If the token or private key is not configured, the SDK will remain inactive and will not send any data.
How to use it
The integration reports exceptions on its own. This is for the reports you send deliberately.
<?php
use function Dock\Ray\captureException;
try {
$order->settle();
} catch (\Throwable $exception) {
captureException($exception);
throw $exception;
}
Knowledge base articles
Other integrations
All integrationsWordPress and WooCommerce Plugin
Explore integrationModule for PrestaShop 1.7.8+, 8.x, and 9.x
Explore integrationPlugin for Joomla 4, 5, and 6
Explore integrationModule for Drupal 10.2+ and 11
Explore integrationModule for Magento 2.4 and Adobe Commerce
Explore integrationPackage for Laravel 10+
Explore integrationBundle for Symfony 6.4+
Explore integrationClient for Django, FastAPI, Flask, and Scripts
Explore integrationStart Monitoring
Connect your first application and get full visibility into what’s happening in production.