CakePHP <3 NewRelic

Installs: 31 530

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 10

Open Issues: 0


1.0.0-beta2 2020-02-17 13:40 UTC

This package is auto-updated.

Last update: 2022-01-17 18:12:41 UTC


You can modify your files like this to have full NewRelic support.

This is a fork of

Things included

  • NewRelic.NewRelic task
  • NewRelic.NewRelic component
  • NewRelicTrait trait
  • NewRelic.NewRelic



First require the NewRelic plugin.

composer require uafrica/cakephp-newrelic

Then load the plugin

bin/cake plugin load NewRelic


Shells have been deprecated since CakePHP 3.6, but are still available for use. Include this snippet in src/Shell/AppShell.php and ensure all your shells extend it.

	public function startup() {
		$this->NewRelic = $this->Tasks->load('NewRelic.NewRelic');
		$this->NewRelic->parameter('params', json_encode($this->params));
		$this->NewRelic->parameter('args', json_encode($this->args));



Commands unfortunately do not offer a simple way to "inject" code into all commands. A trait is offered to handle the NewRelic injection.

Example usage:


namespace App\Command;

use Cake\Console\Arguments;
use Cake\Console\Command;
use Cake\Console\ConsoleIo;
use NewRelic\Traits\NewRelicTrait;

class ChannelsImportCommand extends Command
	use NewRelicTrait;

	public function execute(Arguments $args, ConsoleIo $io)

		//Rest of your command code.


Simply add NewRelic.NewRelic to your $components list


You can use the supplied NewRelicErrorHandlerMiddleware placed in NewRelic\Middleware\NewRelicErrorHandlerMiddleware which extends the built in Cake\Error\Middleware\ErrorHandlerMiddleware. By using this you'll get the NewRelic working and have default CakePHP behavior.



namespace App;

use Cake\Http\BaseApplication;
use Cake\Routing\Middleware\AssetMiddleware;
use Cake\Routing\Middleware\RoutingMiddleware;

 * Application setup class.
 * This defines the bootstrapping logic and middleware layers you
 * want to use in your application.
class Application extends BaseApplication
     * Setup the middleware your application will use.
     * @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to setup.
     * @return \Cake\Http\MiddlewareQueue The updated middleware.
    public function middleware($middleware)
            // Catch any exceptions in the lower layers,
            // and make an error page/response
            // Handle plugin/theme assets like CakePHP normally does.
            // Apply routing

        return $middleware;