PHP code example of o0khoiclub0o / honeybadger-php

1. Go to this page and download the library: Download o0khoiclub0o/honeybadger-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

o0khoiclub0o / honeybadger-php example snippets




use Honeybadger\Honeybadger;

Honeybadger::$config->values(array(
    'api_key' => '[your-api-key]',
));



$app = new Slim(array(
  // ...
));

$app->add(new Honeybadger\Slim(array(
    'api_key'      => '[your-api-key]',
    'project_root' => realpath(__DIR__),
)));

// ...
$app->run();



try
{
  // ...
}
catch (Exception $e)
{
    Honeybadger::notify($e);
}
// ...



Honeybadger::$config->values(array(
    // ...
    'environment_name' => 'production',
));



// To add an additional environment to be ignored:
Honeybadger::$config->development_environments[] = 'staging';

// To override the default environments completely:
Honeybadger::$config->development_environments = array(
    'test', 'behat',
);



$authenticate_user = function() use $app {
  // ...
    if (isset($current_user))
    {
        Honeybadger::context(array(
          'user_id'    => $current_user->id,
          'user_email' => $current_user->email,
        ));
    }
};

// ...

$app->get('/protected_resource', $authenticate_user, function() {
    // ...
});



try
{
    $params = array(
        // Params that you pass to a method that can throw an exception.
    );
    my_unpredictable_method($params);
}
catch (Exception $e)
{
    Honeybadger::notify(array(
        'error_class'   => 'Special Error',
        'error_message' => 'Special Error: '.$e->getMessage(),
        'parameters'    => $params,
    ));
}



array(
    'api_key'       => Honeybadger::$config->api_key,
    'error_message' => 'Notification',
    'backtrace'     => debug_backtrace(),
    'parameters'    => array(),
    'session'       => $_SESSION,
    'context'       => Honeybadger::context(),
);



Honeybadger::$config->ignore[] = 'SomeException';



Honeybadger::$config->ignore_only('RandomError');



Honeybadger::$config->ignore_user_agent[] = 'IgnoredUserAgent';



Honeybadger::$config->ignore_by_filter(function($notice) {
    if ($notice->error_class == 'Exception')
        return TRUE;
});



Honeybadger::$config->params_filters[] = 'credit_card_number';

Honeybadger::$config->values(array(
    'api_key' => '1234567890abcdef',
    'send_request_session' => FALSE,
));



Honeybadger::$config->values(array(
    'proxy_host' => 'proxy.host.com',
    'proxy_port' => 4038,
    'proxy_user' => 'foo', // optional
    'proxy_pass' => 'bar', // optional
));
javascript
{
  // ...
  "honeybadger-php": "*"
  }
  // ...
}
javascript
{
  // ...
  "honeybadger-php": "*"
  }
  // ...
}