---
title: newrelic_background_job (PHP agent API)
source: https://docs.newrelic.com/docs/apm/agents/php-agent/php-agent-api/newrelic_background_job
---

## Syntax

```php
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](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/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 [#mark-as-background]

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

### Mark transaction as a web transaction [#mark-as-web]

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