Skip to content

Commit

Permalink
Merge pull request #135 from rryqszq4/development
Browse files Browse the repository at this point in the history
[pr] Support php 8.1
  • Loading branch information
rryqszq4 authored Nov 30, 2021
2 parents cb67b75 + 6f71b6c commit 73ef8b1
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 15 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ngx_php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
--health-retries=3
strategy:
matrix:
php_version: [7.0.33, 7.1.33, 7.2.34, 7.3.28, 7.4.19, 8.0.6]
php_version: [7.0.33, 7.1.33, 7.2.34, 7.3.33, 7.4.26, 8.0.13, 8.1.0]
ngxinx_version: [1.12.2, 1.16.1]
steps:
- uses: actions/checkout@v2
Expand All @@ -47,8 +47,9 @@ jobs:
run: |
mysql -h 0.0.0.0 -P 33306 -uroot -p${{ secrets.DB_PASSWORD }} -e 'create database ngx_php; grant all on ngx_php.* to "ngx_php"@"%" identified by "ngx_php"; flush privileges;'
if [ ! -d data-cache ]; then mkdir data-cache; fi
if [ ! -f data-cache/world.sql.gz ]; then wget -O data-cache/world.sql.gz http://downloads.mysql.com/docs/world.sql.gz; fi
zcat data-cache/world.sql.gz | mysql -h 0.0.0.0 -P 33306 -uroot -p${{ secrets.DB_PASSWORD }}
if [ ! -f data-cache/world-db.tar.gz ]; then wget -O data-cache/world-db.tar.gz https://downloads.mysql.com/docs/world-db.tar.gz; fi
tar zxvf data-cache/world-db.tar.gz
mysql -h 0.0.0.0 -P 33306 -uroot -p${{ secrets.DB_PASSWORD }} < world-db/world.sql
mysql -h 0.0.0.0 -P 33306 -uroot -p${{ secrets.DB_PASSWORD }} -e 'grant all on world.* to "ngx_php"@"%"; flush privileges;'
./.travis/compiler.sh
- name: test
Expand Down
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ngx_php7 0.0.26 changes:
* Support php version 8.1.0 30 Nov 2021

ngx_php7 0.0.25 changes: 11 Dec 2020
* Support php version 8.0.0

Expand Down
7 changes: 3 additions & 4 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ fi

if [ -z "$NGX_PHP_LIBS" ]; then
PHP_VERSION="`$PHP_CONFIG --version`"
if [ ${PHP_VERSION:0:1} -ge "8" ]; then
PHP_MAJOR_VERSION=`echo $PHP_VERSION | sed -e "s#\.[0-9]*##g"`
if [ $PHP_MAJOR_VERSION -ge "8" ]; then
PHP_MAJOR_VERSION=""
else
PHP_MAJOR_VERSION=${PHP_VERSION:0:1}
fi
NGX_PHP_LIBS="`$PHP_CONFIG --ldflags` `$PHP_CONFIG --libs` -L$PHP_LIB -lphp$PHP_MAJOR_VERSION "
fi
Expand All @@ -91,4 +90,4 @@ else
CORE_LIBS="$CORE_LIBS $NGX_PHP_LIBS "
fi

have=NDK_SET_VAR . auto/have
have=NDK_SET_VAR . auto/have
47 changes: 43 additions & 4 deletions src/ngx_http_php_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ ngx_http_php_code_from_string(ngx_pool_t *pool, ngx_str_t *code_str)


#if PHP_MAJOR_VERSION >= 8
#if PHP_MINOR_VERSION > 0
void
ngx_php_error_cb(int type,
zend_string *error_filename, const uint32_t error_lineno, zend_string *message)
#else
void
ngx_php_error_cb(int type,
const char *error_filename, const uint32_t error_lineno, zend_string *message)
#endif
#else
void
ngx_php_error_cb(int type,
Expand Down Expand Up @@ -145,7 +151,11 @@ ngx_php_error_cb(int type,
#endif
|| (!PG(ignore_repeated_source)
&& ((PG(last_error_lineno) != (int)error_lineno)
#if PHP_MAJOR_VERSION >= 8 && PHP_MINOR_VERSION > 0
|| !zend_string_equals(PG(last_error_file), error_filename)))) {
#else
|| strcmp(PG(last_error_file), error_filename)))) {
#endif
display = 1;
} else {
display = 0;
Expand All @@ -165,15 +175,23 @@ ngx_php_error_cb(int type,
PG(last_error_file) = NULL;
}
if (!error_filename) {
#if PHP_MAJOR_VERSION >= 8 && PHP_MINOR_VERSION >= 1
error_filename = ZSTR_KNOWN(ZEND_STR_UNKNOWN_CAPITALIZED);
#else
error_filename = "Unknown";
#endif
}
PG(last_error_type) = type;
#if PHP_MAJOR_VERSION >= 8
PG(last_error_message) = zend_string_copy(message);
#else
PG(last_error_message) = strdup(buffer);
#endif
#if PHP_MAJOR_VERSION >= 8 && PHP_MINOR_VERSION > 0
PG(last_error_file) = zend_string_copy(error_filename);
#else
PG(last_error_file) = strdup(error_filename);
#endif
PG(last_error_lineno) = error_lineno;
}

Expand Down Expand Up @@ -253,7 +271,13 @@ ngx_php_error_cb(int type,
error_type_str = "Unknown error";
break;
}
buffer_len = spprintf(&log_buffer, 0, "%s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno);
buffer_len = spprintf(&log_buffer, 0, "%s: %s in %s on line %d", error_type_str, buffer,
#if PHP_MAJOR_VERSION >= 8 && PHP_MINOR_VERSION > 0
ZSTR_VAL(error_filename),
#else
error_filename,
#endif
error_lineno);

ngx_buf_t *b;
ngx_http_php_rputs_chain_list_t *chain;
Expand Down Expand Up @@ -671,15 +695,22 @@ ngx_php_ngx_run(ngx_http_request_t *r, ngx_http_php_state_t *state, ngx_http_php

zend_file_handle file_handle;

#if PHP_MAJOR_VERSION < 8 || (PHP_MAJOR_VERSION == 8 && PHP_MINOR_VERSION < 1)
file_handle.type = ZEND_HANDLE_FP;
file_handle.opened_path = NULL;
file_handle.opened_path = NULL;
file_handle.free_filename = 0;
file_handle.filename = code->code.file;
if (!(file_handle.handle.fp = VCWD_FOPEN(file_handle.filename, "rb"))) {
php_printf("Could not open input file: %s\n", file_handle.filename);
return FAILURE;
}
php_execute_script(&file_handle );
#else
zend_stream_init_filename(&file_handle, code->code.file);
if (php_execute_script(&file_handle) == FAILURE) {
php_printf("Failed to execute PHP script.\n");
}
#endif

}else {
}
Expand Down Expand Up @@ -707,15 +738,23 @@ ngx_php_eval_file(ngx_http_request_t *r, ngx_http_php_state_t *state, ngx_http_p

zend_file_handle file_handle;

#if PHP_MAJOR_VERSION < 8 || (PHP_MAJOR_VERSION == 8 && PHP_MINOR_VERSION < 1)
file_handle.type = ZEND_HANDLE_FP;
file_handle.opened_path = NULL;
file_handle.opened_path = NULL;
file_handle.free_filename = 0;
file_handle.filename = code->code.file;
if (!(file_handle.handle.fp = VCWD_FOPEN(file_handle.filename, "rb"))) {
php_printf("Could not open input file: %s\n", file_handle.filename);
return FAILURE;
}
php_execute_script(&file_handle);
php_execute_script(&file_handle );
#else
zend_stream_init_filename(&file_handle, code->code.file);
if (php_execute_script(&file_handle) == FAILURE) {
php_printf("Failed to execute PHP script.\n");
return FAILURE;
}
#endif

}

Expand Down
5 changes: 5 additions & 0 deletions src/ngx_http_php_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,13 @@ char *ngx_http_php_code_read_cookies();
int ngx_http_php_code_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers );

#if PHP_MAJOR_VERSION >= 8
#if PHP_MINOR_VERSION > 0
extern void (*old_zend_error_cb)(int, zend_string *, const uint32_t, zend_string *);
void ngx_php_error_cb(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
#else
extern void (*old_zend_error_cb)(int, const char *, const uint32_t, zend_string *);
void ngx_php_error_cb(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message);
#endif
#else
extern void (*old_zend_error_cb)(int, const char *, const uint, const char *, va_list);
void ngx_php_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
Expand Down
11 changes: 9 additions & 2 deletions src/ngx_http_php_directive.c
Original file line number Diff line number Diff line change
Expand Up @@ -1097,16 +1097,23 @@ ngx_http_php_set_run_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
zend_file_handle file_handle;

retval = NULL;
#if PHP_MAJOR_VERSION < 8 || (PHP_MAJOR_VERSION == 8 && PHP_MINOR_VERSION < 1)
file_handle.type = ZEND_HANDLE_FP;
file_handle.opened_path = NULL;
file_handle.opened_path = NULL;
file_handle.free_filename = 0;
file_handle.filename = filter_data->code->code.file;
if (!(file_handle.handle.fp = VCWD_FOPEN(file_handle.filename, "rb"))) {
php_printf("Could not open input file: %s\n", file_handle.filename);
//return FAILURE;
return NGX_CONF_ERROR;
}
php_execute_simple_script(&file_handle, retval );
#else
zend_stream_init_filename(&file_handle, filter_data->code->code.file);
if (php_execute_simple_script(&file_handle, retval ) == FAILURE) {
php_printf("Failed to execute PHP script.\n");
return NGX_CONF_ERROR;
}
#endif

if (Z_TYPE_P(retval) == IS_TRUE ||
Z_TYPE_P(retval) == IS_FALSE ||
Expand Down
4 changes: 4 additions & 0 deletions src/ngx_http_php_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,11 @@ ngx_module_t ngx_http_php_module = {
ngx_http_request_t *ngx_php_request;

#if PHP_MAJOR_VERSION >= 8
#if PHP_MINOR_VERSION > 0
void (*old_zend_error_cb)(int, zend_string *, const uint32_t, zend_string *);
#else
void (*old_zend_error_cb)(int, const char *, const uint32_t, zend_string *);
#endif
#else
void (*old_zend_error_cb)(int, const char *, const uint, const char *, va_list);
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/ngx_http_php_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef __NGX_HTTP_PHP_VERSION_H__
#define __NGX_HTTP_PHP_VERSION_H__

#define NGX_HTTP_PHP_MODULE_VERSION "0.0.25"
#define NGX_HTTP_PHP_MODULE_VERSION "0.0.26"

#define NGX_HTTP_PHP_MODULE_NAME "ngx_php"

Expand Down
2 changes: 1 addition & 1 deletion t/011-ngx_constants.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ location = /ngx_constants {
--- request
GET /ngx_constants
--- response_body
NGX_HTTP_PHP_MODULE_VERSION = 0.0.25
NGX_HTTP_PHP_MODULE_VERSION = 0.0.26
NGX_HTTP_PHP_MODULE_NAME = ngx_php
NGX_OK = 0
NGX_ERROR = -1
Expand Down

0 comments on commit 73ef8b1

Please sign in to comment.