PHP Troubleshooting Framework Configuration

Agent Configuration

  1. Make sure the agent has been successfully installed (follow the Installation Framework for any issues) and reports the data to your New Relic UI.

  2. The current configuration for PHP (including New Relic Agent settings) can be obtained by visiting the phpinfo() page. It’s important to note that PHP has two interfaces, each can have a different configuration. One is Web interface and the other is Command Line Interface. It is possible to have the agent working only for one of the interfaces.

    1. To see current Web interface configuration access the PHP script where the phpinfo() function is executed from within the web browser.
    2. To see current CLI interface configuration access the PHP script where the phpinfo() function is executed from Command Line or execute php -i call.
  3. Make sure you are editing the correct config file.

    1. All the PHP agent configuration comes from the .ini file. This is not limited to the newrelic.ini file but any .ini file that PHP is configured (compiled) to read. For example, PHP might not be reading anything apart from the main, php.ini configuration file. The newrelic settings would be included within that file then.
    2. To see what directory PHP reads from, check the value of Scan this dir for additional .ini files within the phpinfo() page.
    3. Making any changes to the configuration file requires a server restart in case of the web interface as the .ini file is read at the server startup and settings are loaded to memory.
    4. Making any changes to the configuration file DOES NOT require a server restart in case of the CLI interface as the files are read with each command line invocation.
  4. PHP Agent can also be configured on a Per-Directory basis. This is done through:

    1. http.conf or .htaccess file for Apache.
    2. php-fpm.conf or .user.ini for PHP-FPM.
    3. NGINX config file via fastcgi_param.
  5. Environment variables configuration.

    1. PHP agent does not expect any environment variables to configure agent settings which means you can’t configure, for example, appname via just an environment variable.
    2. You can however include a placeholder variable within the .ini file that would be replaced by environment variables if needed.
  6. Server Side Configuration for the PHP agent.

    1. This is not available for the PHP agent.
  7. Configuration within the code using API calls:

    1. The agent can be configured within the code using the API functions available here.
  8. Configuration order of precedence.

    1. .ini -> per-directory -> API.
  9. Distributed Tracing.

    1. By default, distributed tracing is set to false. You need to edit your configuration file to enable this option.

Daemon Configuration

  1. Daemon configuration lives within the .ini file with a prefix of newrelic.daemon.

  2. If the file /etc/newrelic/newrelic.cfg exists, the daemon settings in the .ini file are ignored and the daemon will not start automatically.

    1. You are required to start the daemon manually and configure the daemon settings within the newrelic.cfg file.

Containerized Environments Configuration

  1. Running the agent and the daemon in separate containers:

    1. This is the recommended approach. It requires you to set up two containers - one with the application and the PHP agent, and the other with the daemon.
    2. Start the daemon with the --address and the --watchdog-foreground arguments. This sets the port on which the daemon will be listed for incoming connections from the PHP agent.
    3. Configure the PHP agent to look for the daemon in another container by setting newrelic.daemon.address to HOST:PORT value. In docker-compose for example, this is the value of the service name in your docker-compose.yml file. Docker will be able to resolve the address by the name reference.
    4. An example application utilizing this approach is available here.
  2. Running the agent and the daemon in the same container:

    1. The installation of the agent happens within the Dockerfile. It mimics the steps you would perform on a server to install the agent.
    2. It is recommended to use silent mode install which eliminates user input needs. Silent mode is set via environment variables as explained here.
    3. An example Dockerfile is available in the documentation.

Monitoring short lived processes/containers.

  1. In a default installation, the first transaction initiates daemon start and connection to New Relic collectors. This can result in the first few transactions to be lost as the agent does not wait for the connection to finish. In scenarios where one monitors a container that starts up just to execute a single transaction, it is required to configure the following so that this transaction isn’t lost:

    1. [newrelic.daemon.start_timeout]( to 5s
    2. [newrelic.daemon.app_connect_timeout]( to 15s
  2. In containerized application, this works best with a daemon being run in a separate container as the daemon startup time is removed (assuming it already runs elsewhere).

1 Like