newrelic_background_job([bool $flag])
Manually specify that a transaction is a background job or a web transaction.

Description

Tell the agent to treat this "web" transaction as a "non-web" transaction (the APM UI separates web and non-web transactions, for example in the Transactions page). Call as early as possible. This is most commonly used for cron jobs or other long-lived background tasks. However, this call is usually unnecessary since the agent usually detects whether a transaction is a web or non-web transaction automatically.

You can also reverse the functionality by setting the optional flag to false, which marks a "non-web" transaction as a "web" transaction.

Parameters

Parameter Description

$flag

boolean

Optional. Defaults to true.

If ‚Äčtrue or omitted, the current transaction is marked as a background job.

If false, the transaction is marked as a web transaction.

Example(s)

Mark transaction as a background job

function example() {
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
	    newrelic_background_job();
    }
    ...
}

Mark transaction as a web transaction

function example() {
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
	    newrelic_background_job(false);
    }
    ...
}