CodeIgniter 3

note: This is the documentation for version 3 of CodeIgniter. See the documentation to integrate Raygun into a CodeIgniter 4 app here.


Use Composer to add the Raygun4PHP package to your CodeIgniter 3 project. Run the following command in a shell at the root of your project:

composer require "mindscape/raygun4php:2.*"

Inside of /application/config/config.php ensure that enable_hooks is set to true:

$config['enable_hooks'] = TRUE;

Create a file at /application/hooks/RaygunSetup.php. This file is going to create the RaygunClient and setup the error/exception handlers.

Add the following content to that new file. Making sure to substitute the apiKey.

use GuzzleHttp\Client;
use Raygun4php\RaygunClient;
use Raygun4php\Transports\GuzzleAsync;
use Raygun4php\Transports\GuzzleSync;

require_once 'vendor/autoload.php';

class RaygunSetup {
    private static $raygunClient;

    public function __construct() {
        $httpClient = new Client([
            'base_uri' => '',
            'headers' => [
                'X-ApiKey' => 'paste_your_api_key_here'

        $transport = new GuzzleAsync($httpClient);

        self::$raygunClient = new RaygunClient($transport);

        register_shutdown_function([$transport, 'wait']);

    public function set_exception_handler() {
        set_exception_handler( array( $this,'exception_handler' ) );
        set_error_handler( array( $this, "error_handler" ) );

    function exception_handler($exception) {
        echo 'Exception thrown';

    function error_handler( $errno, $errstr, $errfile, $errline) {
        self::$raygunClient->SendError($errno, $errstr, $errfile, $errline);

In application/config/hooks.php wire up the pre_controller hook to the above RaygunSetup.

$hook['pre_controller'] = array(
    'class'    => 'RaygunSetup',
    'function' => 'set_exception_handler',
    'filename' => 'RaygunSetup.php',
    'filepath' => 'hooks'

Deploy Raygun into your production environment for best results, or raise a test exception. Once we detect your first error event, the Raygun app will automatically update.

The provider is open source and available at the Raygun4PHP repository.