What is an abstract socket and why would I use it?
The New Relic PHP Agent is made up of two parts: the PHP extension which collects data from your apps and the
newrelic-daemon which holds that data until it can be sent to the New Relic servers.
By default, PHP connects to the daemon using a socket file,
/tmp/.newrelic.sock. This works across different Unix systems and normally isn’t an issue.
On some systems, particularly those with Selinux, PHP may not be able to connect to this socket file due to security settings. You’ll see something like the following in the
2017-11-21 11:56:14.596 -0800 (11576 11576) warning: daemon connect(fd=5 uds=/tmp/.newrelic.sock) returned -1 errno=ECONNREFUSED. Failed to connect to the newrelic-daemon.
When this occurs, we recommend using an abstract socket. This is a Linux feature which creates a virtual socket that is not affected by file permissions. You can read more about Linux sockets here:
How to configure abstract sockets
1) Edit your
newrelic.ini and change the following:
;newrelic.daemon.port = "/tmp/.newrelic.sock"
newrelic.daemon.port = "@newrelic-daemon"
2) Kill any newrelic-daemon processes currently running. Something like this:
kill `pgrep newrelic-daemon`
3) Restart your PHP handler (Apache/FPM/etc) to pick up the change. By default this will also restart the newrelic-daemon on the new socket.
4) Confirm it is listening on the new socket. There will be two
newrelic-daemon processes normally.
[root@roger ~]# ps aux | grep newrelic-daemon root 518 0.0 0.3 187968 5832 ? Ssl 07:27 0:00 /usr/bin/newrelic-daemon --agent --pidfile /var/run/newrelic-daemon.pid --logfile /var/log/newrelic/newrelic-daemon.log --port @newrelic-daemon --tls --define utilization.detect_aws=true --define utilization.detect_azure=true -- define utilization.detect_gcp=true --define utilization.detect_pcf=true --define utilization.detect_docker=true
Keep in mind…
These settings need to be the same across your system so if your command line PHP uses a different configuration than your web based PHP you will need to update both newrelic.ini files to use the same socket. Otherwise your command line PHP might start the daemon on the default /tmp socket while your web based PHP is still looking for it on the abstract socket.
Also, if you are using external startup mode (using an init script to start the daemon) you will need to update the
port setting in your
/etc/newrelic/newrelic.cfg to the same abstract socket.