<?phpRollbar::report_message('could not connect to mysql server', Level::WARNING);Rollbar::report_message('Here is a message with some additional data',Level::INFO, array('x'=>10, 'code'=>'blue'));?>

Batching

By default, payloads are batched and sent to the Rollbar servers at the end of every script execution via a shutdown handler, or when the batch size reaches 50, whichever comes first. This works well in standard short-lived scripts, like serving web requests.

If you're using Rollbar in a long-running script, such as a Laravel project or a background worker, you may want to manually flush the batch. To flush, simply call:

Rollbar::flush();

For example, if using Laravel, add the above line to your App::after() event handler. Or in a looping background worker, call it at the end of each loop.

You can also tune the max batch size or disable batching altogether. See the batch_size and batched config variables, documented below.

Configuration

Asynchronous Reporting

By default, payloads (batched or not) are sent as part of script execution. This is easy to configure but may negatively impact performance. With some additional setup, payloads can be written to a local relay file instead; that file will be consumed by rollbar-agent asynchronously. To turn this on, set the following config params:

<?php$config=array(// ... rest of current config'handler'=>'agent','agent_log_location'=>'/var/www'// not including final slash. must be writeable by the user php runs as.);?>

code_version
The currently-deployed version of your code/application (e.g. a Git SHA). Should be a string.

Default: null

enable_utf8_sanitization
set to false, to disable running iconv on the payload, may be needed if there is invalid characters, and the payload is being destroyed

Default: true

environment
Environment name, e.g. 'production' or 'development'

Default: 'production'

error_sample_rates
Associative array mapping error numbers to sample rates. Sample rates are ratio out of 1, e.g. 0 is "never report", 1 is "always report", and 0.1 is "report 10% of the time". Sampling is done on a per-error basis.

Default: empty array, meaning all errors are reported.

handler
Either 'blocking' or 'agent'. 'blocking' uses curl to send requests immediately; 'agent' writes a relay log to be consumed by rollbar-agent.

Default: 'blocking'

host
Server hostname.

Default: null, which will result in a call to gethostname() (or php_uname('n') if that function does not exist)

include_error_code_context
A boolean that indicates you wish to gather code context for instances of PHP Errors.
This can take a while because it requires reading the file from disk, so it's off by default.

Default: false

include_exception_code_context
A boolean that indicates you wish to gather code context for instances of PHP Exceptions.
This can take a while because it requires reading the file from disk, so it's off by default.

Default: false

included_errno
A bitmask that includes all of the error levels to report. E.g. (E_ERROR | E_WARNING) to only report E_ERROR and E_WARNING errors. This will be used in combination with error_reporting() to prevent reporting of errors if use_error_reporting is set to true.

logger
An object that has a log($level, $message) method. If provided, will be used by RollbarNotifier to log messages.

person
An associative array containing data about the currently-logged in user. Required: id, optional: username, email. All values are strings.

person_fn
A function reference (string, etc. - anything that call_user_func() can handle) returning an array like the one for 'person'.

root
Path to your project's root dir

scrub_fields
Array of field names to scrub out of _POST and _SESSION. Values will be replaced with asterisks. If overriding, make sure to list all fields you want to scrub, not just fields you want to add to the default. Param names are converted to lowercase before comparing against the scrub list.

<?php$config['error_sample_rates'] =array(// E_WARNING omitted, so defaults to 1E_NOTICE=>0.1,E_USER_ERROR=>0.5,// E_USER_WARNING will take the same value, 0.5E_USER_NOTICE=>0.1,// E_STRICT and beyond will all be 0.1);?>