CodeIgniter — Lescopr SDK

Integrate the Lescopr SDK into your CodeIgniter application using the vanilla PHP bootstrap for automatic exception and error capture.

Introduction

The Lescopr PHP SDK integrates with CodeIgniter through the lightweight vanilla PHP bootstrap — LescoprBootstrap::init().

A single line added to your entry point hooks into PHP's native error handling (set_error_handler, set_exception_handler, register_shutdown_function) and starts forwarding all errors and exceptions to your Lescopr dashboard.

The package is available on Packagist and is compatible with CodeIgniter 4+ and PHP 7.4+.

Requirements

Before installing the Lescopr SDK, make sure your environment meets the following requirements:

  • PHP >= 7.4
  • CodeIgniter >= 4.0
  • Composer >= 2.0
  • A valid LESCOPR_SDK_KEY and LESCOPR_API_KEY (available from your Lescopr dashboard)

Recommended: ext-pcntl and ext-posix for the background daemon. Without them, the SDK operates in direct HTTP mode.

Installation

Install the package via Composer:

Then add the bootstrap call at the top of your public/index.php, after the Composer autoloader:

Terminal
bash
composer require lescopr/lescopr-php
public/index.php
php
<?php
require 'vendor/autoload.php';

\Lescopr\Integrations\Vanilla\LescoprBootstrap::init();

// Your existing CodeIgniter bootstrap continues unchanged

Configuration

The simplest approach is to use .lescopr.json generated by the CLI:

Alternatively, pass configuration directly to init() without a config file:

Available options:

  • sdk_key — Your Lescopr SDK key (required)
  • api_key — Your Lescopr API key (required)
  • environment — The current environment (production, staging, development)
  • debug — Enables verbose output to .lescopr.log (default: false)
Terminal
bash
./vendor/bin/lescopr init --sdk-key YOUR_SDK_KEY
public/index.php
php
\Lescopr\Integrations\Vanilla\LescoprBootstrap::init([
    'sdk_key'     => 'lsk_xxxx',
    'api_key'     => 'lak_xxxx',
    'environment' => 'production',
    'debug'       => false,
]);

Usage

Once the bootstrap is initialised, the SDK installs three native PHP handlers automatically:

  • set_error_handler — captures all PHP errors (E_WARNING, E_NOTICE, etc.)
  • set_exception_handler — captures all uncaught exceptions
  • register_shutdown_function — captures fatal errors (E_ERROR, E_PARSE, etc.)

You can also log events and report exceptions manually from anywhere in your application:

app/Controllers/Home.php
php
use Lescopr\Core\Lescopr;

$sdk = Lescopr::getInstance();
$sdk->log('info', 'User visited home page', ['user_id' => $userId]);

try {
    $this->model->processOrder($data);
} catch (\Throwable $e) {
    $sdk->report($e);
    throw $e;
}

Advanced

CLI initialisation

Initialise the SDK from the command line. This detects your framework, registers the project with the API, writes .lescopr.json, and starts the daemon:

Environment variables

  • LESCOPR_SDK_KEY — SDK key (overrides .lescopr.json)
  • LESCOPR_API_KEY — API key
  • LESCOPR_ENVIRONMENT — development or production
  • LESCOPR_DAEMON_MODE=true — Prevents the SDK from forking inside its own daemon
  • LESCOPR_DEBUG=true — Enables verbose output to .lescopr.log
Terminal
bash
./vendor/bin/lescopr init --sdk-key YOUR_SDK_KEY --environment production
Terminal
bash
./vendor/bin/lescopr start
./vendor/bin/lescopr status
./vendor/bin/lescopr diagnose --details