PHP

Library for PHP Applications

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:

bash
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:

php
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.

Articles in this category

DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.