CakePHP <3 NewRelic
You can modify your files like this, (*1)
Things included
- NewRelic.NewRelic task
- NewRelic.NewRelic component
- NewRelicTrait trait
- NewRelic.NewRelic
Installation
composer require jippi/cakephp-newrelic
Console
Include this snippet in app/Console/AppShell.php
, (*2)
public function startup() {
$this->NewRelic = $this->Tasks->load('NewRelic.NewRelic');
$this->NewRelic->setName($this);
$this->NewRelic->start();
$this->NewRelic->parameter('params', json_encode($this->params));
$this->NewRelic->parameter('args', json_encode($this->args));
parent::startup();
}
Controller
Simply add NewRelic.NewRelic
to your $components
list, (*3)
app/webroot/index.php
Add this in top of your file before define('DS', 'DIRECTORY_SEPARATOR')
, (*4)
CakePHP 3.3.0 and using middleware
If you utilise CakePHP middlewares from https://book.cakephp.org/3.0/en/controllers/middleware.html
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.
Example:
```php
add(\NewRelic\Middleware\NewRelicErrorHandlerMiddleware::class)
// Handle plugin/theme assets like CakePHP normally does.
->add(AssetMiddleware::class)
// Apply routing
->add(RoutingMiddleware::class);
return $middleware;
}
}
?>