According to the arm64 newrelic php page there is arm64 support for the php agent, if it is running Amazon Linux or CentOS Linux8, but not for Apple or M1.
However, when I pulled the latest tar.gz (v10.4.0.316 as of 2023/01/13) at https://github.com/newrelic/newrelic-php-agent/archive/refs/tags/v10.4.0.316.tar.gz and tried to compile - it did nearly work.
The first tries of make agent
, will fail with missing pcre_compile
or aclocal
or glibtoolize
. This can be fixed by
installing brew install pcre
for pcre_compile
, brew install automake
for aclocal
and brew install libtool
for glibtoolize
.
Then finally running make agent
ends up in:
util_hash.c:198:5: error: unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
case 2:
^
util_hash.c:198:5: note: insert '__attribute__((fallthrough));' to silence this warning
case 2:
^
__attribute__((fallthrough));
util_hash.c:198:5: note: insert 'break;' to avoid fall-through
case 2:
^
break;
As a quick fix I did:
diff --git a/axiom/Makefile b/axiom/Makefile
index 5339697..ee970f8 100644
--- a/axiom/Makefile
+++ b/axiom/Makefile
@@ -51,7 +51,7 @@ ifeq (1,$(HAVE_CLANG))
AXIOM_CFLAGS += -Wbool-conversion
AXIOM_CFLAGS += -Wempty-body
AXIOM_CFLAGS += -Wheader-hygiene
-AXIOM_CFLAGS += -Wimplicit-fallthrough
+#AXIOM_CFLAGS += -Wimplicit-fallthrough
AXIOM_CFLAGS += -Wlogical-op-parentheses
AXIOM_CFLAGS += -Wloop-analysis
AXIOM_CFLAGS += -Wsizeof-array-argument
Running make agent
again ended up in:
/newrelic-php-agent/agent/php_autorum.c:24:17: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
return (char*)emalloc(len);
^~~~~~~~~~~~
/opt/homebrew/Cellar/[email protected]/8.1.14/include/php/Zend/zend_alloc.h:157:28: note: expanded from macro 'emalloc'
#define emalloc(size) _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/homebrew/Cellar/[email protected]/8.1.14/include/php/Zend/zend_alloc.h:111:3: note: expanded from macro '_emalloc'
ZEND_ALLOCATOR(size) \
^~~~~~~~~~~~~~~~~~~~
/opt/homebrew/Cellar/[email protected]/8.1.14/include/php/Zend/zend_alloc.h:106:9: note: expanded from macro 'ZEND_ALLOCATOR'
((size <= ZEND_MM_MAX_LARGE_SIZE) ? _emalloc_large(size) : _emalloc_huge(size)) \
~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
In this case I figured a fix like this:
diff --git a/agent/php_autorum.c b/agent/php_autorum.c
index bd701b0..afc3d13 100644
--- a/agent/php_autorum.c
+++ b/agent/php_autorum.c
@@ -21,7 +21,7 @@
static char* nr_php_rum_malloc(int len) {
nrl_verbosedebug(NRL_AUTORUM, "autorum: resizing buffer to %d bytes", len);
- return (char*)emalloc(len);
+ return (char*)emalloc((unsigned)len);
}
/*
The build succeded and I ran make agent-install
. The result was:
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C agent install
Installing shared extensions: /opt/homebrew/Cellar/[email protected]/8.1.14/pecl/20210902/
I created the /opt/homebrew/etc/php/8.1/conf.d/20-newrelic.ini
with
[newrelic]
extension="/opt/homebrew/Cellar/[email protected]/8.1.14/pecl/20210902/newrelic.so"
But checking newrelic.daemon.location
in php -i
it says there must be a daemon executable at /usr/bin/newrelic-daemon,
which does not exist.
To avoid messages like: warning: couldn't find daemon='/usr/bin/newrelic-daemon' (ENOENT)
, we need to create the daemon, too.
To make the daemon buildable, be sure to have golang executable available (with brew install go
).
Then build the daemon like this: make daemon
- it will have no output. But you have a binary at bin/daemon
afterwards.
Copy this binary to the target location at /usr/local/bin/newrelic-daemon
(we cannot use the default of /usr/bin/newrelic-daemon
as it is not writable in macosx).
Then adjust the /opt/homebrew/etc/php/8.1/conf.d/20-newrelic.ini
accordingly
[newrelic]
extension="/opt/homebrew/Cellar/[email protected]/8.1.14/pecl/20210902/newrelic.so"
newrelic.daemon.location=/usr/bin/newrelic-daemon
If you check the log after executing either php-fpm or a cli script, it will look like this:
info: New Relic 10.4.0.0 ("goldenrod" - "") [daemon='/tmp/.newrelic.sock' php='8.1.14' zts=no sapi='fpm-fcgi' pid=63812 ppid=1 uid=0 euid=0 gid=0 egid=0 backtrace=yes startup=agent os='Darwin' rel='21.6.0' mach='arm64' ver='Darwin Kernel Version 21.6.0' node='IDONOTTELLYOU.local']
warning: A global default license has not been set or has invalid format. Please add a 'newrelic.license' key in the global php.ini or in the newrelic.ini file, or ensure that a valid license is provided on a per-virtual host or per-directory basis
So don't forget to set newrelic.license
as php.ini value or use in your php code newrelicsetappname
with newrelic_set_appname(string $name, string $license[, bool $xmit])
to set also the application name and the license at the same time.
To have life a bit easier I contributed this as pull request #2433 to homebrew-extensions. Thus you can save all of this, by just running:
$ brew tap shivammathur/extensions
$ brew install shivammathur/extensions/[email protected]
and that's it. It is supported on arm64/x64 and even on linuxbrew - with bottles, so no compiling necessary. That's nice.