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

## Syntax

```php
newrelic_end_transaction([bool $ignore])
```

Stop instrumenting the current transaction immediately.

## Requirements

Agent version [3.0.5.95](https://docs.newrelic.com/docs/release-notes/agent-release-notes/php-release-notes/php-agent) or higher.

## Description

Stop instrumenting the current transaction immediately, and send the data to the daemon. This call simulates what the agent normally does when PHP terminates the current transaction. The most common use for this call is to improve instrumentation of command line scripts that handle job queue processing. Call this method at the end of a particular job, and then call [`newrelic_start_transaction()`](https://docs.newrelic.com/docs/agents/php-agent/php-agent-api/newrelic_start_transaction) when a new task is pulled off the queue.

Normally, when you end a transaction you want the agent to record the associated data. However, you can also discard the data by setting `$ignore` to `true`.

> #### 💡 TIP
>
> Compare [`newrelic_end_of_transaction()`](https://docs.newrelic.com/docs/agents/php-agent/php-agent-api/newrelic_end_of_transaction), which stops timing the transaction but continues to instrument it.

## Parameters

| Parameter           | Description                                                                                                                                                                            |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$ignore` _boolean_ | Optional. Defaults to `false`. If `false` or omitted, data from the transaction **is** recorded by the daemon. If `true`, data from the transaction **is not** recorded by the daemon. |

## Return values

Returns `true` if the transaction was successfully ended and data was sent to the New Relic daemon.

## Examples

### Stop a transaction, then start another [#stop-and-start]

```php
function example() {
    // queuing logic
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
        newrelic_end_transaction(); // stop recording the current transaction
        newrelic_start_transaction(ini_get("newrelic.appname")); // start recording a new transaction
    }
    // more queuing logic
}
```

### Stop instrumenting entirely [#stop-entirely]

```php
function example() {
    // this code is instrumented
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
        newrelic_end_transaction();
    }
    // this code is ignored
}
```
