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

## Syntax

```php
newrelic_start_transaction(string $appname[, string $license])
```

Starts a new transaction, usually after manually ending a transaction.

## 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

Start a new transaction manually. Usually used after manually ending a transaction with `newrelic_end_transaction()`, for example when separating tasks in a job queue manager. When instrumenting this new transaction, the agent performs the same operations as when the script first started.

## Parameters

| Parameter           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$appname` _string_ | Required. The [application name](https://docs.newrelic.com/docs/agents/manage-apm-agents/app-naming/name-your-application) to associate with data from this transaction. Uses the same format as [`newrelic.appname`](https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-newrelicini-settings#inivar-appname) and can set multiple application names by separating each with a semicolon `;`. While this option is required, you can read the app name from `newrelic.ini` with `ini_get("newrelic.appname")`. |
| `$license` _string_ | Optional. Defaults to the license key set in the New Relic agent's `newrelic.ini` file. Provide a different license key if you want the transaction to report to a different New Relic account. If set, this license will supersede all per-directory and global default licenses configured in INI files.                                                                                                                                                                                                                          |

## Return values

This function will return `true` if the transaction was successfully started.

## Examples

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

For task queue managers, you can use `newrelic_end_transaction()` and `newrelic_start_transaction()` together to manually separate transactions. This example uses `ini_get` to read the application name from the config file.

```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
}
```

### Start a new transaction with a new license key [#start-license-key]

This example manually specifies the app name and the license key:

```php
function example() {
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
        newrelic_start_transaction("App1", "01234567890abcde01234567890abcde01234567890");
    }
    ...
}
```
