• /
  • Log in
  • Free account
Docs

newrelic_background_job (PHP agent API)

Syntax

newrelic_background_job([bool $flag])

Manually specify that a transaction is a background job or a web transaction.

Requirements

Compatible with all agent versions.

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.

Examples

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);
    }
    ...
}

For more help

If you need more help, check out these support and learning resources:

Docs
Create issueEdit page
Copyright © 2021 New Relic Inc.