The PHP agent comes in two parts:
- The PHP extension module
- The agent daemon
The daemon acts as a proxy between the PHP agent and the New Relic collector to reduce network traffic and to improve response time for instrumented applications. If the daemon is not running, no data is reported to New Relic.
PHP daemon initial or idle states
When the daemon is in an initial or idle state, two transactions must occur before it will start reporting.
In an initial state:
- With the first transaction, the daemon adds your newly-reporting application to its own application information table.
- Once the application is added, the daemon reports the second transaction to New Relic.
In an idle state:
- The first transaction wakes up the daemon and re-establishes the connection to New Relic.
- The second transaction reports data to New Relic.
Watchdog and worker processes
If you do a process listing, you will see that there are always two daemon processes running:
$ ps -ef | grep newrelic-daemon newrelic 1368 1 0 00:28 ? 00:00:00 /usr/bin/newrelic-daemon ... newrelic 1370 1368 0 00:28 ? 00:00:00 /usr/bin/newrelic-daemon ...
Having two processes running is normal behavior. The first column is the process owner, the second is the process ID (PID), and the third is the parent process ID (PPID).
|Watchdog (first process)||
The first process, the one owned by PID 1, is the "watchdog" process. It watches the second process, which is the "worker" process.
|Worker (second process)||
The worker process does the following:
When the daemon is being gracefully terminated (usually by running
If you need to manually terminate the daemon, always terminate the watchdog, not the worker.
If the worker process encounters a fatal error and terminates unexpectedly, the watchdog process will immediately re-spawn a new worker process. This helps to ensure that the daemon experiences absolute minimum downtime.
Stop the daemon
The following methods can be used to kill the daemon:
Recommended process: Use
/etc/init.d/newrelic-daemon stop. This is the preferred method for interacting with the daemon.
Kill the process directly with its process ID:
Use the watchdog PID file:
kill `cat /var/run/newrelic-daemon.pid`