Star us on GitHub
Star
Menu

Using highlight.io with PHP Frameworks

Learn how to set up highlight.io on your PHP backend.

1

Configure client-side Highlight. (optional)

If you're using Highlight on the frontend for your application, make sure you've initialized it correctly and followed the fullstack mapping guide.

2

Install the Highlight PHP SDK via Composer.

Run the following command to install the Highlight SDK for PHP:

composer require highlight/php-sdk
Copy
3

Initialize the Highlight PHP SDK.

To initialize the Highlight backend SDK, use one of the initializer methods:

use Highlight\SDK\Common\HighlightOptions; use Highlight\SDK\Highlight; $projectId = '<YOUR_PROJECT_ID>'; // Use only a projectId to bootstrap Highlight if (!Highlight::isInitialized()) { Highlight::init($projectId); } // Use a HighlightOptions instance to bootstrap Highlight $options = HighlightOptions::builder($projectId)->build(); if (!Highlight::isInitialized()) { Highlight::initWithOptions($options); } // Use a HighlightOptions instance prepped with a serviceName to bootstrap Highlight $options = HighlightOptions::builder($projectId)->serviceName('test-service-01')->build(); if (!Highlight::isInitialized()) { Highlight::initWithOptions($options); }
Copy
4

Verify your errors are being recorded.

Now that you've set up the Middleware, verify that the backend error handling works by consuming an error from traced code.

5

Record custom errors. (optional)

If you want to explicitly send an error to Highlight, you can use the Highlight::captureException() method.

use Highlight\SDK\Highlight; Highlight::captureException(new \Exception('This is a test exception'));
Copy
6

Add Highlight logger.

Highlight.captureLog() will record and send logs to Highlight.

use Highlight\SDK\Highlight; $logger = Highlight::HighlightLogger(Highlight::$highlight) $logger->process(Highlight::HighlightLogRecordBuilder()->build());
Copy
7

Verify your backend logs are being recorded.

Visit the highlight logs portal and check that backend logs are coming in.

8

Record a trace.

Use the Highlight SDK to create spans and events.

use Highlight\SDK\Highlight; $tracer = Highlight::HighlightLogger(Highlight::$highlight) $tracer->process(Highlight::HighlightErrorRecord()->build());
Copy
9

Verify your backend traces are being recorded.

Visit the highlight traces portal and check that backend traces are coming in.