PHP agent API

The PHP agent API allows you to extend the functionality of the PHP agent. The agent API is included by default with your installation, so no additional configuration is required to use the agent.

Among other things, you can use the API to customize your app name; collect errors; record custom attributes, custom events, and custom metrics; and enable or disable New Relic Browser.

Enclose these API calls in a conditional check for the PHP agent so that your code will work even if the agent is not present:

if (extension_loaded('newrelic')) {
  newrelic_set_appname($name);
}
newrelic_add_custom_parameter
Attaches a custom attribute (key/value pair) to the current transaction.
newrelic_add_custom_tracer
Specify functions or methods for the agent to instrument with custom instrumentation.
newrelic_background_job
Manually specify that a transaction is a background job or a web transaction.
newrelic_capture_params
Enable or disable the capture of URL parameters.
newrelic_custom_metric
Add a custom metric (in milliseconds) to time a component of your app not captured by default.
newrelic_disable_autorum
Disable automatic injection of the New Relic Browser snippet on particular pages.
newrelic_end_of_transaction
Stop timing the current transaction, but continue instrumenting it.
newrelic_end_transaction
Stop instrumenting the current transaction immediately.
Returns a New Relic Browser snippet to inject at the end of the HTML output.
newrelic_get_browser_timing_header
Returns a New Relic Browser snippet to inject in the head of your HTML output.
newrelic_ignore_apdex
Ignore the current transaction when calculating Apdex.
newrelic_ignore_transaction
Do not instrument the current transaction.
newrelic_name_transaction
Set custom name for current transaction.
newrelic_notice_error
Report an error at this line of code and collect a complete stack trace.
newrelic_record_custom_event
Record a custom event with the given name and attributes.
newrelic_set_appname
Sets the New Relic app name, which controls data rollup.
newrelic_set_user_attributes
Create user-related custom attributes. newrelic_add_custom_parameter is more flexible.
newrelic_start_transaction
Starts a new transaction, usually after manually ending a transaction.