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_KEYandLESCOPR_API_KEY(available from your Lescopr dashboard)
Recommended:
ext-pcntlandext-posixfor 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:
composer require lescopr/lescopr-php<?php
require 'vendor/autoload.php';
\Lescopr\Integrations\Vanilla\LescoprBootstrap::init();
// Your existing CodeIgniter bootstrap continues unchangedConfiguration
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)
./vendor/bin/lescopr init --sdk-key YOUR_SDK_KEY\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 exceptionsregister_shutdown_function— captures fatal errors (E_ERROR,E_PARSE, etc.)
You can also log events and report exceptions manually from anywhere in your application:
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 keyLESCOPR_ENVIRONMENT—developmentorproductionLESCOPR_DAEMON_MODE=true— Prevents the SDK from forking inside its own daemonLESCOPR_DEBUG=true— Enables verbose output to.lescopr.log
./vendor/bin/lescopr init --sdk-key YOUR_SDK_KEY --environment production./vendor/bin/lescopr start
./vendor/bin/lescopr status
./vendor/bin/lescopr diagnose --details