Skip to content

Commit f0d52d5

Browse files
bduranleau-nrZNeumannlavaroumfulb
authored
feat(agent): add support for PHP 8.2 (#627)
Co-authored-by: ZNeumann <[email protected]> Co-authored-by: Michal Nowacki <[email protected]> Co-authored-by: Michael Fulbright <[email protected]> Co-authored-by: mfulb <[email protected]>
1 parent 2faca76 commit f0d52d5

File tree

74 files changed

+1521
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1521
-194
lines changed

.github/workflows/agent-build.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ on:
1818
push:
1919
branches:
2020
- main
21-
- 'php8'
2221
- 'dev'
2322
pull_request:
2423
branches:
2524
- main
26-
- 'php8'
2725
- 'dev'
2826

2927
jobs:
@@ -38,7 +36,7 @@ jobs:
3836
strategy:
3937
matrix:
4038
os: [linux]
41-
php_ver: ['7.0', '7.1-zts', '7.2', '7.3', '7.4', '8.0', '8.0-zts', '8.1', '8.1-zts']
39+
php_ver: ['7.0', '7.1-zts', '7.2', '7.3', '7.4', '8.0', '8.0-zts', '8.1', '8.1-zts', '8.2']
4240
arch: ['x64', 'x86']
4341
exclude:
4442
# Excludes PHP 5.x, 7.x on linux 32-bit
@@ -70,6 +68,9 @@ jobs:
7068
- os: linux
7169
php_ver: '8.1-zts'
7270
arch: 'x86'
71+
- os: linux
72+
php_ver: '8.2'
73+
arch: 'x86'
7374
steps:
7475
- name: Checkout Repo
7576
uses: actions/checkout@v2

.github/workflows/release-build.yml

+28-36
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,45 @@ on:
1616
# Run this workflow manually from the Actions tab or using the API
1717
#
1818
workflow_dispatch:
19+
inputs:
20+
build-number:
21+
description: 'Build number for agent version'
22+
required: true
23+
type: string
1924

2025
jobs:
2126
agent_release:
2227
env:
23-
PHP_VER: ${{ matrix.php_ver }}
24-
ARCH: ${{ matrix.arch }}
25-
BUILD_TYPE: release
26-
OS: ${{ matrix.os }}
27-
image_name: ${{ matrix.os }}:${{ matrix.php_ver }}${{ matrix.arch }}
28+
IMAGE_NAME: newrelic/nr-php-agent-builder
29+
IMAGE_VERSION: v1
2830
runs-on: ubuntu-latest
2931
strategy:
3032
matrix:
31-
os: [linux]
32-
php_ver: ['8.0-zts']
33-
arch: [x64, x86]
33+
platform: [gnu, musl]
34+
php_ver: ['8.2']
35+
arch: [amd64]
3436
steps:
3537
- name: Checkout Repo
36-
uses: actions/checkout@v2
38+
uses: actions/checkout@v3
3739
with:
3840
ref: ${{ github.event.client_payload.ref }}
39-
- name: Build Custom Docker Image
40-
run: docker build --build-arg ARCH=$ARCH --build-arg PHP_VER=$PHP_VER --build-arg BUILD_TYPE=$BUILD_TYPE -f ./.github/docker/${OS}/${ARCH}/Dockerfile -t $image_name .
41-
- name: Build and Test
42-
run: docker run --name runtest --workdir /github/workspace --rm -e GITHUB_WORKSPACE -e GITHUB_ENV -v "${GITHUB_WORKSPACE}":"/github/workspace" $image_name
43-
- name: Save build artifacts
44-
uses: actions/upload-artifact@v2
45-
with:
46-
name: ${{ matrix.php_ver }}binaries
47-
path: releases
48-
if-no-files-found: error
49-
combine:
50-
if: ${{ always() }}
51-
runs-on: ubuntu-latest
52-
name: Combine artifacts from matrix build
53-
needs: agent_release
54-
steps:
55-
- name: Create directory
56-
run: mkdir releases
57-
- name: Download to directory
58-
uses: actions/download-artifact@v2
41+
path: newrelic-php-agent
42+
- name: Login to Docker Hub
43+
uses: docker/login-action@v2
5944
with:
60-
path: releases
61-
- run: sudo apt install tree
62-
- run: tree
63-
- name: Upload artifacts
64-
uses: actions/upload-artifact@v2
45+
username: ${{ secrets.DOCKERHUB_USERNAME }}
46+
password: ${{ secrets.DOCKERHUB_TOKEN }}
47+
- name: Build
48+
run: >
49+
docker run --rm --platform linux/${{matrix.arch}}
50+
-v "${GITHUB_WORKSPACE}/newrelic-php-agent":"/usr/local/src/newrelic-php-agent"
51+
-e OPTIMIZE=1
52+
-e PCRE_STATIC=yes
53+
-e BUILD_NUMBER=${{inputs.build-number}}
54+
$IMAGE_NAME:agent-builder-php${{matrix.php_ver}}-${{matrix.platform}}-$IMAGE_VERSION release-${{matrix.php_ver}}-gha
55+
- name: Save build artifacts
56+
uses: actions/upload-artifact@v3
6557
with:
66-
name: $GITHUB_SHA
67-
path: releases
58+
path: newrelic-php-agent/releases
59+
name: release-from-gha
6860
if-no-files-found: error

Makefile

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ GIT ?= git
1515
include make/config.mk
1616
include make/vendor.mk
1717
include make/version.mk
18+
include make/php_versions.mk
1819

1920
# Include the secrets file if it exists, but if it doesn't, that's OK too.
2021
-include make/secrets.mk
@@ -328,7 +329,7 @@ src/newrelic/infinite_tracing/com_newrelic_trace_v1/v1.pb.go: protocol/infinite_
328329

329330
.PHONY: integration
330331
integration: Makefile daemon lasp-test-all integration-events-limits
331-
for PHP in $${PHPS:-8.1 8.0 7.4 7.3 7.2 7.1 7.0 5.6 5.5}; do \
332+
for PHP in $(PHP_VERSION_LIST); do \
332333
echo; echo "# PHP=$${PHP}"; \
333334
env NRLAMP_PHP=$${PHP} bin/integration_runner $(INTEGRATION_ARGS) || exit 1; \
334335
echo "# PHP=$${PHP}"; \
@@ -354,7 +355,7 @@ integration-events-limits: daemon
354355
custom_limits_tests[7000]=583; \
355356
custom_limits_tests[30000]=2500; \
356357
custom_limits_tests[100000]=8333; \
357-
for PHP in $${PHPS:-8.1 8.0 7.4 7.3 7.2 7.1 7.0 5.6 5.5}; do \
358+
for PHP in $(PHP_VERSION_LIST); do \
358359
echo; echo "# PHP=$${PHP}"; \
359360
for custom_max in "$${!custom_limits_tests[@]}"; do \
360361
collector_limit=$${custom_limits_tests[$$custom_max]}; \
@@ -367,7 +368,7 @@ integration-events-limits: daemon
367368

368369
# test for invalid value (-1) and (1000000)
369370
# Should use default (30000) for -1 and max (100000) for 1000000
370-
for PHP in $${PHPS:-8.1 8.0 7.4 7.3 7.2 7.1 7.0 5.6 5.5}; do \
371+
for PHP in $(PHP_VERSION_LIST); do \
371372
env NRLAMP_PHP=$${PHP} bin/integration_runner $(INTEGRATION_ARGS) \
372373
-max_custom_events 100000 \
373374
tests/event_limits/custom/test_custom_events_max_samples_stored_invalid_toolarge_limit.php || exit 1; \
@@ -379,7 +380,7 @@ integration-events-limits: daemon
379380

380381
# also run a test where limit is set to 0
381382
# default value is used
382-
for PHP in $${PHPS:-8.1 8.0 7.4 7.3 7.2 7.1 7.0 5.6 5.5}; do \
383+
for PHP in $(PHP_VERSION_LIST); do \
383384
env NRLAMP_PHP=$${PHP} bin/integration_runner $(INTEGRATION_ARGS) \
384385
-max_custom_events 0 \
385386
tests/event_limits/custom/test_custom_events_max_samples_stored_0_limit.php || exit 1; \
@@ -388,7 +389,7 @@ integration-events-limits: daemon
388389

389390
# also run a test where no agent custom event limit is specified and verify
390391
# default value is used
391-
for PHP in $${PHPS:-8.1 8.0 7.4 7.3 7.2 7.1 7.0 5.6 5.5}; do \
392+
for PHP in $(PHP_VERSION_LIST); do \
392393
env NRLAMP_PHP=$${PHP} bin/integration_runner $(INTEGRATION_ARGS) \
393394
-max_custom_events 30000 \
394395
tests/event_limits/custom/test_custom_events_max_samples_stored_not_specified.php || exit 1; \
@@ -454,7 +455,7 @@ lasp-test: daemon
454455
if [ ! $(SUITE_LASP) ]; then echo "USAGE: make lasp-test SUITE_LASP=suite-most-secure"; exit 1; fi
455456
@if [ "$(LICENSE_lasp_$(subst -,_,$(SUITE_LASP)))" = "" ] ; then echo "Missing license for $(SUITE_LASP)"; exit 1; fi
456457
if [ ! -d "tests/lasp/$(SUITE_LASP)" ]; then echo "No such suite in tests/lasp folder"; exit 1; fi
457-
@for PHP in $${PHPS:-8.1 8.0 7.4 7.3 7.2 7.1 7.0 5.6 5.5}; do \
458+
@for PHP in $(PHP_VERSION_LIST); do \
458459
echo; echo "# PHP=$${PHP}"; \
459460
NRLAMP_PHP=$${PHP} bin/integration_runner $(INTEGRATION_ARGS) -loglevel debug \
460461
-license $(LICENSE_lasp_$(subst -,_,$(SUITE_LASP))) \

agent/newrelic-install.sh

+9
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ add_to_path /usr/local/php-7.3/bin
543543
add_to_path /usr/local/php-7.4/bin
544544
add_to_path /usr/local/php-8.0/bin
545545
add_to_path /usr/local/php-8.1/bin
546+
add_to_path /usr/local/php-8.2/bin
546547

547548
add_to_path /opt/local/bin
548549
add_to_path /usr/php/bin
@@ -556,6 +557,7 @@ add_to_path /usr/php-7.3/bin
556557
add_to_path /usr/php-7.4/bin
557558
add_to_path /usr/php-8.0/bin
558559
add_to_path /usr/php-8.1/bin
560+
add_to_path /usr/php-8.2/bin
559561

560562
add_to_path /usr/php/5.5/bin
561563
add_to_path /usr/php/5.6/bin
@@ -566,6 +568,7 @@ add_to_path /usr/php/7.3/bin
566568
add_to_path /usr/php/7.4/bin
567569
add_to_path /usr/php/8.0/bin
568570
add_to_path /usr/php/8.1/bin
571+
add_to_path /usr/php/8.2/bin
569572

570573
add_to_path /opt/php/bin
571574
add_to_path /opt/zend/bin
@@ -579,6 +582,7 @@ add_to_path /opt/php-7.3/bin
579582
add_to_path /opt/php-7.4/bin
580583
add_to_path /opt/php-8.0/bin
581584
add_to_path /opt/php-8.1/bin
585+
add_to_path /opt/php-8.2/bin
582586

583587
if [ -n "${NR_INSTALL_PATH}" ]; then
584588
oIFS="${IFS}"
@@ -1065,6 +1069,10 @@ for this copy of PHP. We apologize for the inconvenience.
10651069
pi_php8="yes"
10661070
;;
10671071

1072+
8.2.*)
1073+
pi_php8="yes"
1074+
;;
1075+
10681076
*)
10691077
error "unsupported version '${pi_ver}' of PHP found at:
10701078
${pdir}
@@ -1233,6 +1241,7 @@ does not exist. This particular instance of PHP will be skipped.
12331241
7.4.*) pi_modver="20190902" ;;
12341242
8.0.*) pi_modver="20200930" ;;
12351243
8.1.*) pi_modver="20210902" ;;
1244+
8.2.*) pi_modver="20220829" ;;
12361245
esac
12371246
log "${pdir}: pi_modver=${pi_modver}"
12381247

agent/php_call.c

+26-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ zval* nr_php_call_user_func(zval* object_ptr,
1515
zend_uint param_count,
1616
zval* params[] TSRMLS_DC) {
1717
#if ZEND_MODULE_API_NO >= ZEND_7_0_X_API_NO /* PHP 7.0+ */
18+
#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
19+
zend_object* object = NULL;
20+
zend_string* method_name = NULL;
21+
#endif
1822
int zend_result = FAILURE;
1923
zval* fname = NULL;
2024
HashTable* symbol_table = NULL;
@@ -48,8 +52,29 @@ zval* nr_php_call_user_func(zval* object_ptr,
4852

4953
fname = nr_php_zval_alloc();
5054
nr_php_zval_str(fname, function_name);
51-
#if ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO /* PHP 8.0+ */
55+
#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO /* PHP 8.2+ */
56+
/*
57+
* With PHP 8.2, functions that do not exist will cause a fatal error to
58+
* be thrown. `zend_call_method_if_exists` will attempt to call a function and
59+
* silently fail if it does not exist
60+
*/
61+
if (NULL != object_ptr) {
62+
object = Z_OBJ_P(object_ptr);
63+
} else {
64+
object = NULL;
65+
}
66+
67+
if (NULL != fname) {
68+
method_name = Z_STR_P(fname);
69+
} else {
70+
return NULL;
71+
}
72+
73+
zend_result = zend_call_method_if_exists(object, method_name, retval,
74+
param_count, param_values);
5275

76+
#elif ZEND_MODULE_API_NO < ZEND_8_2_X_API_NO \
77+
&& ZEND_MODULE_API_NO >= ZEND_8_0_X_API_NO
5378
/*
5479
* With PHP8, `call_user_function_ex` was removed and `call_user_function`
5580
* became the recommended function.

agent/php_includes.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#define ZEND_7_4_X_API_NO 20190902
5353
#define ZEND_8_0_X_API_NO 20200930
5454
#define ZEND_8_1_X_API_NO 20210902
55+
#define ZEND_8_2_X_API_NO 20220829
5556

5657
#if ZEND_MODULE_API_NO >= ZEND_5_6_X_API_NO
5758
#include "Zend/zend_virtual_cwd.h"

agent/php_nrini.c

+6
Original file line numberDiff line numberDiff line change
@@ -2980,10 +2980,16 @@ STD_PHP_INI_ENTRY_EX("newrelic.application_logging.metrics.enabled",
29802980
PHP_INI_END() /* } */
29812981

29822982
void nr_php_register_ini_entries(int module_number TSRMLS_DC) {
2983+
#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
2984+
int type = MODULE_PERSISTENT;
2985+
#endif
29832986
REGISTER_INI_ENTRIES();
29842987
}
29852988

29862989
void nr_php_unregister_ini_entries(int module_number TSRMLS_DC) {
2990+
#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
2991+
int type = MODULE_PERSISTENT;
2992+
#endif
29872993
UNREGISTER_INI_ENTRIES();
29882994
}
29892995

agent/tests/tlib_php.c

+6
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,15 @@ nr_status_t tlib_php_engine_create(const char* extra_ini PTSRMLS_DC) {
301301
/*
302302
* Actually start the Zend Engine.
303303
*/
304+
#if ZEND_MODULE_API_NO >= ZEND_8_2_X_API_NO
305+
if (FAILURE == php_module_startup(&tlib_module, &newrelic_module_entry)) {
306+
return NR_FAILURE;
307+
}
308+
#else
304309
if (FAILURE == php_module_startup(&tlib_module, &newrelic_module_entry, 1)) {
305310
return NR_FAILURE;
306311
}
312+
#endif
307313

308314
/*
309315
* As noted above, we now replace the interned string callbacks on PHP

axiom/nr_app_harvest.c

+19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@
1212
#include "nr_app_harvest_private.h"
1313
#include "util_logging.h"
1414

15+
/*
16+
* The build pipeline for PHP 8.2 uses a Debian image that is built on a
17+
* version of glibc that contains an newer glibc version symbol for `pow()`
18+
* which is incompatible with older distributions, causing RPM installs to fail.
19+
*
20+
* To pin the version of `pow` to a version compatible with all NR PHP Agent
21+
* supported OSes, we utilize `asm()` and `.symver` to instruct the linker to
22+
* select an older version of the symbol.
23+
*/
24+
#if defined(__GLIBC__)
25+
#if (((__GLIBC__) > 2) || (((__GLIBC__) == 2) && ((__GLIBC_MINOR__) > 17)))
26+
#if defined (__x86_64__)
27+
__asm__(".symver pow,pow@GLIBC_2.2.5");
28+
#elif defined (__aarch64__)
29+
__asm__(".symver pow,pow@GLIBC_2.17");
30+
#endif
31+
#endif
32+
#endif
33+
1534
void nr_app_harvest_init(nr_app_harvest_t* ah,
1635
nrtime_t connect_timestamp,
1736
nrtime_t harvest_frequency,

files/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
ARG PHP_VER
1111

12-
FROM php:${PHP_VER:-8.0}
12+
FROM php:${PHP_VER:-8.2}
1313

1414
RUN docker-php-source extract
1515

make/php_versions.mk

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Copyright 2023 New Relic Corporation. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
PHP_VERSION_LIST=$${PHPS:-8.2 8.1 8.0 7.4 7.3 7.2 7.1 7.0 5.6 5.5}

make/release.mk

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# the top-level of the project.
1111
#
1212

13+
include make/php_versions.mk
14+
1315
RELEASE_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
1416
RELEASE_OS := $(RELEASE_OS:darwin=osx)
1517
RELEASE_OS := $(RELEASE_OS:sunos=solaris)
@@ -40,17 +42,15 @@ ifeq (osx,$(RELEASE_OS))
4042
endif
4143
endif
4244

43-
# Set the default PHP versions we will build.
44-
PHPS?=8.1 8.0 7.4 7.3 7.2 7.1 7.0 5.6 5.5
4545
# Set the PHP versions we support on 64-bit OSs.
46-
SUPPORTED_64=8.1 8.0 7.4 7.3 7.2 7.1 7.0 5.6 5.5
46+
SUPPORTED_64=$(PHP_VERSION_LIST)
4747
# Set the PHP versions we support on 32-bit OSs.
4848
SUPPORTED_32=
4949
# Of the PHP versions we want to build, determine which are supported on the detected OS.
5050
ifeq (x64,$(ARCH))
51-
SUPPORTED_PHP = $(filter $(SUPPORTED_64),$(PHPS))
51+
SUPPORTED_PHP = $(filter $(SUPPORTED_64),$(PHP_VERSION_LIST))
5252
else
53-
SUPPORTED_PHP = $(filter $(SUPPORTED_32),$(PHPS))
53+
SUPPORTED_PHP = $(filter $(SUPPORTED_32),$(PHP_VERSION_LIST))
5454
endif
5555

5656

@@ -144,6 +144,7 @@ release-$1-zts: Makefile agent | releases/$$(RELEASE_OS)/agent/$$(RELEASE_ARCH)/
144144

145145
endef
146146

147+
$(eval $(call RELEASE_AGENT_TARGET,8.2,20220829))
147148
$(eval $(call RELEASE_AGENT_TARGET,8.1,20210902))
148149
$(eval $(call RELEASE_AGENT_TARGET,8.0,20200930))
149150
$(eval $(call RELEASE_AGENT_TARGET,7.4,20190902))

0 commit comments

Comments
 (0)