Inspector logo

PHP

Build Status Latest Stable Version

Install the latest version by:

composer require inspector-apm/inspector-php

Use

To start sending data to Inspector you need an API key to create a configuration instance. You can obtain INSPECTOR_API_KEY creating a new project in your Inspector dashboard.

<?php
require __DIR__ . '/../vendor/autoload.php';

use Inspector\Inspector;
use Inspector\Configuration;

$configuration = new Configuration('YOUR_API_KEY');
$inspector = new Inspector($configuration);

Start a transaction

All start with a transaction. Transaction represent an execution cycle and it can contains one or hundred of segments.

// Start a transaction
$inspector->startTransaction($_SERVER['PATH_INFO']);

By default the transaction will closed automatically after your application has sent the response to the user. You can close the transaction manually if you want.

// Close a transaction
$inspector->end();

Segments

After a transaction is started you can segmenting your script execution with multiple segments that measures the timing needed by a code block to be executed.

// Monitor the execution of a part of your script
$segment = $inspector->startSegment('my-process');
try {

    throw new UnauthorizedException("You don't have permission to access.");

} catch(UnauthorizedException $exception) {
    $inspector->reportException($exception);
} fianlly {
    $segment->end();
}

Remember to close every segment opened, so use finally keyword in a try/catch code block.

Put all together

<?php
require __DIR__ . '/../vendor/autoload.php';

use Inspector\Inspector;
use Inspector\Configuration;

$configuration = new Configuration('YOUR_API_KEY');
$inspector = new Inspector($configuration);

// Monitor the execution of a part of your script
$segment = $inspector->startSegment('my-process');
try {

    throw new UnauthorizedException("You don't have permission to access.");

} catch(UnauthorizedException $exception) {
    $inspector->reportException($exception);
} fianlly {
    $segment->end();
}

Options

Proxy

Inspector library supports data delivery through proxy. Specify proxy using libcurl format: [protocol://][user:password@]proxyhost[:port]

$configuration = new Inspector\Configuration(
    'YOUR_API_KEY', 
    ['proxy' => 'https://55.88.22.11:3128']
);

Curl path

It can be useful to specify curl destination path for AsyncTransport. This option is set to 'curl' by default.

$configuration = new Inspector\Configuration(
    'YOUR_API_KEY', 
    ['curlPath' => '/usr/bin/curl']
);