diff options
author | Alejandro Colomar <alx.manpages@gmail.com> | 2023-01-27 14:14:43 +0100 |
---|---|---|
committer | Andrew Clayton <a.clayton@nginx.com> | 2023-01-27 14:45:52 +0000 |
commit | 0686740f2053abf2b398c6620bb2e74090209fc6 (patch) | |
tree | 0c4de704e2d9277157e9f089503df2cec9885c08 | |
parent | 05c56394587ae9bda36ce7e481af12caf76b5252 (diff) | |
download | unit-0686740f2053abf2b398c6620bb2e74090209fc6.tar.gz unit-0686740f2053abf2b398c6620bb2e74090209fc6.tar.bz2 |
PHP: Factored out code into a helper function.
We're going to use zend_stream_init_filename in a following commit. To
reduce the diff of that change, move the current code that will be
replaced, to a function that has the same interface.
We use strlen(3) here to be able to use an interface without passing the
length, but we will remove that call in a following code, so it has no
performance issues.
Co-developed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Cc: Andrei Zeliankou <zelenkov@nginx.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
-rw-r--r-- | src/nxt_php_sapi.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/nxt_php_sapi.c b/src/nxt_php_sapi.c index d2494938..0358ebdf 100644 --- a/src/nxt_php_sapi.c +++ b/src/nxt_php_sapi.c @@ -106,6 +106,8 @@ static nxt_int_t nxt_php_do_301(nxt_unit_request_info_t *req); static void nxt_php_request_handler(nxt_unit_request_info_t *req); static void nxt_php_dynamic_request(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r); +static void nxt_zend_stream_init_filename(zend_file_handle *handle, + const char *filename); static void nxt_php_execute(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r); nxt_inline void nxt_php_vcwd_chdir(nxt_unit_request_info_t *req, u_char *dir); @@ -1110,6 +1112,21 @@ nxt_php_dynamic_request(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r) static void +nxt_zend_stream_init_filename(zend_file_handle *handle, const char *filename) +{ + nxt_memzero(handle, sizeof(zend_file_handle)); + + handle->type = ZEND_HANDLE_FILENAME; +#if (PHP_VERSION_ID >= 80100) + handle->filename = zend_string_init(filename, strlen(filename), 0); + handle->primary_script = 1; +#else + handle->filename = filename; +#endif +} + + +static void nxt_php_execute(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r) { #if (PHP_VERSION_ID < 50600) @@ -1179,16 +1196,8 @@ nxt_php_execute(nxt_php_run_ctx_t *ctx, nxt_unit_request_t *r) nxt_php_vcwd_chdir(ctx->req, ctx->script_dirname.start); } - nxt_memzero(&file_handle, sizeof(file_handle)); - - file_handle.type = ZEND_HANDLE_FILENAME; -#if (PHP_VERSION_ID >= 80100) - file_handle.filename = zend_string_init((char *) ctx->script_filename.start, - ctx->script_filename.length, 0); - file_handle.primary_script = 1; -#else - file_handle.filename = (char *) ctx->script_filename.start; -#endif + nxt_zend_stream_init_filename(&file_handle, + (const char *) ctx->script_filename.start); php_execute_script(&file_handle TSRMLS_CC); |