Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1]Sync code from master branch #5362

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 56 additions & 54 deletions .github/workflows/ext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,72 @@ name: ext-swoole

on: [push, pull_request]

env:
CPPFLAGS: "-I/opt/homebrew/opt/pcre2/include/"

jobs:
build-ubuntu-latest:
if: "!contains(github.event.head_commit.message, '[test]')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: install-deps
run: sudo apt update -y && sudo apt install -y libcurl4-openssl-dev php-curl libc-ares-dev
- name: phpize
run: phpize
- name: build1
run: ./configure &&
make clean && make -j$(nproc)
- name: build2
run: ./configure --enable-sockets &&
make clean && make -j$(nproc)
- name: build3
run: ./configure --enable-sockets --enable-mysqlnd &&
make clean && make -j$(nproc)
- name: build5
run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl &&
make clean && make -j$(nproc)
- name: build6
run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl --enable-debug-log &&
make clean && make -j$(nproc)
- name: build7
run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-debug-log &&
make clean && make -j$(nproc)
- name: build8
run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-cares --enable-debug-log &&
make clean && make -j$(nproc)
- name: build with thread context
run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-cares --enable-debug-log --enable-thread-context &&
make clean && make -j$(nproc)
- uses: actions/checkout@v4
- name: install-deps
run: sudo apt update -y && sudo apt install -y libcurl4-openssl-dev php-curl libc-ares-dev
- name: phpize
run: phpize
- name: build1
run: ./configure &&
make clean && make -j$(nproc)
- name: build2
run: ./configure --enable-sockets &&
make clean && make -j$(nproc)
- name: build3
run: ./configure --enable-sockets --enable-mysqlnd &&
make clean && make -j$(nproc)
- name: build5
run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl &&
make clean && make -j$(nproc)
- name: build6
run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl --enable-debug-log &&
make clean && make -j$(nproc)
- name: build7
run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-debug-log &&
make clean && make -j$(nproc)
- name: build8
run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-cares --enable-debug-log &&
make clean && make -j$(nproc)
- name: build with thread context
run: ./configure --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-openssl --enable-cares --enable-debug-log --enable-thread-context &&
make clean && make -j$(nproc)

build-macos-latest:
if: "!contains(github.event.head_commit.message, '[test]')"
runs-on: macos-latest
steps:
- name: install dependencies
run: brew install openssl && brew link openssl && brew install curl && brew link curl && brew install c-ares && brew link c-ares
- uses: actions/checkout@v4
- name: phpize
run: phpize
- name: build1
run: ./configure && make clean && make -j$(sysctl -n hw.ncpu)
- name: build2
run: ./configure --enable-sockets &&
make clean && make -j$(sysctl -n hw.ncpu)
- name: build3
run: ./configure --enable-sockets --enable-mysqlnd &&
make clean && make -j$(sysctl -n hw.ncpu)
- name: build5
run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl
--with-openssl-dir=/usr/local/opt/[email protected] &&
make clean && make -j$(sysctl -n hw.ncpu)
- name: build6
run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl --enable-swoole-curl --enable-debug-log
--with-openssl-dir=/usr/local/opt/[email protected] &&
make clean && make -j$(sysctl -n hw.ncpu)
- name: build7
run: ./configure --enable-sockets --enable-mysqlnd --enable-openssl --enable-swoole-curl --enable-debug-log --enable-cares
--with-openssl-dir=/usr/local/opt/[email protected] &&
make clean && make -j$(sysctl -n hw.ncpu)
- name: install dependencies
run: brew reinstall php
- uses: actions/checkout@v4
- name: phpize
run: phpize
- name: build1
run: ./configure CPPFLAGS="${CPPFLAGS}" && make clean && make -j$(sysctl -n hw.ncpu)
- name: build2
run: ./configure CPPFLAGS="${CPPFLAGS}" --enable-sockets &&
make clean && make -j$(sysctl -n hw.ncpu)
- name: build3
run: ./configure CPPFLAGS="${CPPFLAGS}" --enable-sockets --enable-mysqlnd &&
make clean && make -j$(sysctl -n hw.ncpu)
- name: build5
run: ./configure CPPFLAGS="${CPPFLAGS}" --enable-sockets --enable-mysqlnd --enable-openssl &&
make clean && make -j$(sysctl -n hw.ncpu)
- name: build6
run: ./configure CPPFLAGS="${CPPFLAGS}" --enable-sockets --enable-mysqlnd --enable-openssl
--enable-swoole-curl --enable-debug-log &&
make clean && make -j$(sysctl -n hw.ncpu)
- name: build7
run: ./configure CPPFLAGS="${CPPFLAGS}" --enable-sockets --enable-mysqlnd --enable-openssl --enable-swoole-curl
--enable-debug-log --enable-cares &&
make clean && make -j$(sysctl -n hw.ncpu)

build-alpine-latest:
if: "!contains(github.event.head_commit.message, '[test]')"
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
pull_request:

env:
CPPFLAGS: "-I/opt/homebrew/opt/pcre2/include/"

jobs:
linux:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -120,10 +123,8 @@ jobs:

- name: Build Swoole
run: |
brew install openssl && brew link openssl
brew install c-ares && brew link c-ares
phpize
./configure --enable-openssl --with-openssl-dir=/usr/local/opt/[email protected] --enable-mysqlnd --enable-swoole-curl --enable-cares
./configure CPPFLAGS="${CPPFLAGS}" --enable-openssl --enable-mysqlnd --enable-swoole-curl --enable-cares
make -j$(sysctl -n hw.ncpu)
sudo make install
php --ri swoole
Expand Down
57 changes: 40 additions & 17 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ if test "$PHP_SWOOLE" != "no"; then
AC_CHECK_LIB(pthread, pthread_mutexattr_setrobust, AC_DEFINE(HAVE_PTHREAD_MUTEXATTR_SETROBUST, 1, [have pthread_mutexattr_setrobust]))
AC_CHECK_LIB(pthread, pthread_mutex_consistent, AC_DEFINE(HAVE_PTHREAD_MUTEX_CONSISTENT, 1, [have pthread_mutex_consistent]))
AC_CHECK_LIB(pcre, pcre_compile, AC_DEFINE(HAVE_PCRE, 1, [have pcre]))
AC_CHECK_LIB(cares, ares_gethostbyname, AC_DEFINE(HAVE_CARES, 1, [have c-ares]))

if test "$PHP_SWOOLE_DEV" = "yes"; then
AX_CHECK_COMPILE_FLAG(-Wbool-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wbool-conversion")
Expand Down Expand Up @@ -400,6 +399,9 @@ if test "$PHP_SWOOLE" != "no"; then
fi

if test "$PHP_SWOOLE_CURL" = "yes"; then
PKG_CHECK_MODULES([CURL], [libcurl >= 7.56.0])
PHP_EVAL_LIBLINE($CURL_LIBS, SWOOLE_SHARED_LIBADD)
PHP_EVAL_INCLINE($CURL_CFLAGS)
AC_DEFINE(SW_USE_CURL, 1, [do we enable cURL native client])
fi

Expand Down Expand Up @@ -837,15 +839,24 @@ EOF
PHP_ADD_LIBRARY(z, 1, SWOOLE_SHARED_LIBADD)
])

if test "$PHP_BROTLI" = "yes"; then
AC_CHECK_LIB(brotlienc, BrotliEncoderCreateInstance, [
AC_CHECK_LIB(brotlidec, BrotliDecoderCreateInstance, [
AC_DEFINE(SW_HAVE_COMPRESSION, 1, [have compression])
AC_DEFINE(SW_HAVE_BROTLI, 1, [have brotli encoder])
PHP_ADD_LIBRARY(brotlienc, 1, SWOOLE_SHARED_LIBADD)
PHP_ADD_LIBRARY(brotlidec, 1, SWOOLE_SHARED_LIBADD)
])
])
if test "$PHP_BROTLI" != "no" || test "$PHP_BROTLI_DIR" != "no"; then
if test "$PHP_BROTLI_DIR" != "no"; then
PHP_ADD_INCLUDE("${PHP_BROTLI_DIR}/include")
PHP_ADD_LIBRARY_WITH_PATH(brotli, "${PHP_BROTLI_DIR}/${PHP_LIBDIR}")
PHP_ADD_LIBRARY_WITH_PATH(brotlienc, "${PHP_BROTLI_DIR}/${PHP_LIBDIR}")
PHP_ADD_LIBRARY_WITH_PATH(brotlidec, "${PHP_BROTLI_DIR}/${PHP_LIBDIR}")
else
PKG_CHECK_MODULES([BROTLIENC], [libbrotlienc])
PHP_EVAL_LIBLINE($BROTLIENC_LIBS, SWOOLE_SHARED_LIBADD)
PHP_EVAL_INCLINE($BROTLIENC_CFLAGS)

PKG_CHECK_MODULES([BROTLIDEC], [libbrotlidec])
PHP_EVAL_LIBLINE($BROTLIDEC_LIBS, SWOOLE_SHARED_LIBADD)
PHP_EVAL_INCLINE($BROTLIDEC_CFLAGS)
fi

AC_DEFINE(SW_HAVE_COMPRESSION, 1, [have compression])
AC_DEFINE(SW_HAVE_BROTLI, 1, [have brotli encoder])
fi

PHP_ADD_LIBRARY(pthread)
Expand Down Expand Up @@ -894,8 +905,11 @@ EOF
fi

if test "$PHP_CARES" = "yes"; then
PKG_CHECK_MODULES([CARES], [libcares])
PHP_EVAL_LIBLINE($CARES_LIBS, SWOOLE_SHARED_LIBADD)
PHP_EVAL_INCLINE($CARES_CFLAGS)
AC_DEFINE(SW_USE_CARES, 1, [do we enable c-ares support])
PHP_ADD_LIBRARY(cares, 1, SWOOLE_SHARED_LIBADD)
AC_DEFINE(HAVE_CARES, 1, [have c-ares])
fi

AC_SWOOLE_CPU_AFFINITY
Expand Down Expand Up @@ -944,13 +958,23 @@ EOF
fi

if test "$PHP_OPENSSL" != "no" || test "$PHP_OPENSSL_DIR" != "no"; then
if test "$PHP_OPENSSL_DIR" != "no"; then
if test "$PHP_OPENSSL_DIR" != "no"; then
PHP_ADD_INCLUDE("${PHP_OPENSSL_DIR}/include")
PHP_ADD_LIBRARY_WITH_PATH(ssl, "${PHP_OPENSSL_DIR}/${PHP_LIBDIR}")

PHP_ADD_LIBRARY(ssl, 1, SWOOLE_SHARED_LIBADD)
PHP_ADD_LIBRARY(crypto, 1, SWOOLE_SHARED_LIBADD)
else
PKG_CHECK_MODULES([SSL], [libssl])
PHP_EVAL_LIBLINE($SSL_LIBS, SWOOLE_SHARED_LIBADD)
PHP_EVAL_INCLINE($SSL_CFLAGS)

PKG_CHECK_MODULES([CRYPTO], [libcrypto])
PHP_EVAL_LIBLINE($CRYPTO_LIBS, SWOOLE_SHARED_LIBADD)
PHP_EVAL_INCLINE($CRYPTO_CFLAGS)
fi

AC_DEFINE(SW_USE_OPENSSL, 1, [enable openssl support])
PHP_ADD_LIBRARY(ssl, 1, SWOOLE_SHARED_LIBADD)
PHP_ADD_LIBRARY(crypto, 1, SWOOLE_SHARED_LIBADD)
fi

if test "$PHP_BROTLI_DIR" != "no"; then
Expand All @@ -963,7 +987,6 @@ EOF
fi

if test "$PHP_NGHTTP2_DIR" != "no"; then
AC_DEFINE(SW_USE_SYSTEM_LIBNGHTTP2, 1, [Use the system libnghttp2])
PHP_ADD_INCLUDE("${PHP_NGHTTP2_DIR}/include")
PHP_ADD_LIBRARY_WITH_PATH(nghttp2, "${PHP_NGHTTP2_DIR}/${PHP_LIBDIR}")
PHP_ADD_LIBRARY(nghttp2, 1, SWOOLE_SHARED_LIBADD)
Expand Down Expand Up @@ -1006,8 +1029,7 @@ EOF
thirdparty/php/sockets/conversions.cc \
thirdparty/php/sockets/sockaddr_conv.cc \
thirdparty/php/standard/var_decoder.cc \
thirdparty/php/standard/proc_open.cc \
thirdparty/php83/Zend/zend_call_stack.cc"
thirdparty/php/standard/proc_open.cc"

swoole_source_file="$swoole_source_file \
thirdparty/swoole_http_parser.c \
Expand Down Expand Up @@ -1232,5 +1254,6 @@ EOF
if test "$PHP_SWOOLE_SQLITE" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php80/pdo_sqlite)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php81/pdo_sqlite)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php83/pdo_sqlite)
fi
fi
25 changes: 8 additions & 17 deletions ext-src/php_swoole_call_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,16 @@
+----------------------------------------------------------------------+
*/

#pragma once

#include "php_swoole.h"

#ifdef ZEND_CHECK_STACK_LIMIT
#include "thirdparty/php83/Zend/zend_call_stack.h"
#endif

#ifdef ZEND_CHECK_STACK_LIMIT
#define HOOK_PHP_CALL_STACK(exp) \
zend_call_stack __stack; \
zend_call_stack_get(&__stack); \
auto __stack_base = EG(stack_base); \
auto __stack_limit = EG(stack_limit); \
EG(stack_base) = __stack.base; \
EG(stack_limit) = zend_call_stack_limit(__stack.base, __stack.max_size, EG(reserved_stack_size)); \
exp \
EG(stack_base) = __stack_base; \
EG(stack_limit) = __stack_limit;
#define HOOK_PHP_CALL_STACK(callback) \
auto __stack_limit = EG(stack_limit); \
auto __stack_base = EG(stack_base); \
EG(stack_base) = (void *) 0; \
EG(stack_limit) = (void *) 0; \
callback EG(stack_limit) = __stack_limit; \
EG(stack_base) = __stack_base;
#else
#define HOOK_PHP_CALL_STACK(exp) exp
#define HOOK_PHP_CALL_STACK(callback) callback
#endif
34 changes: 18 additions & 16 deletions ext-src/swoole_http_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,15 @@ bool swoole_http_token_list_contains_value(const char *at, size_t length, const
static int http_request_on_header_value(swoole_http_parser *parser, const char *at, size_t length) {
HttpContext *ctx = (HttpContext *) parser->data;
zval *zheader = ctx->request.zheader;
char *header_name = ctx->current_header_name;
size_t header_len = ctx->current_header_name_len;
char header_name[header_len];
zend_str_tolower_copy(header_name, ctx->current_header_name, header_len);

if (ctx->parse_cookie && SW_STREQ(header_name, header_len, "cookie")) {
if (ctx->parse_cookie && SW_STRCASEEQ(header_name, header_len, "cookie")) {
zval *zcookie = swoole_http_init_and_read_property(
swoole_http_request_ce, ctx->request.zobject, &ctx->request.zcookie, SW_ZSTR_KNOWN(SW_ZEND_STR_COOKIE));
swoole_http_parse_cookie(zcookie, at, length);
return 0;
} else if (SW_STREQ(header_name, header_len, "upgrade") &&
} else if (SW_STRCASEEQ(header_name, header_len, "upgrade") &&
swoole_http_token_list_contains_value(at, length, "websocket")) {
ctx->websocket = 1;
if (ctx->co_socket) {
Expand All @@ -372,7 +371,7 @@ static int http_request_on_header_value(swoole_http_parser *parser, const char *
}
} else if ((parser->method == PHP_HTTP_POST || parser->method == PHP_HTTP_PUT ||
parser->method == PHP_HTTP_DELETE || parser->method == PHP_HTTP_PATCH) &&
SW_STREQ(header_name, header_len, "content-type")) {
SW_STRCASEEQ(header_name, header_len, "content-type")) {
if (SW_STR_ISTARTS_WITH(at, length, "application/x-www-form-urlencoded")) {
ctx->request.post_form_urlencoded = 1;
} else if (SW_STR_ISTARTS_WITH(at, length, "multipart/form-data")) {
Expand All @@ -387,11 +386,11 @@ static int http_request_on_header_value(swoole_http_parser *parser, const char *
}
}
#ifdef SW_HAVE_COMPRESSION
else if (ctx->enable_compression && SW_STREQ(header_name, header_len, "accept-encoding")) {
else if (ctx->enable_compression && SW_STRCASEEQ(header_name, header_len, "accept-encoding")) {
ctx->set_compression_method(at, length);
}
#endif
else if (SW_STREQ(header_name, header_len, "transfer-encoding") && SW_STR_ISTARTS_WITH(at, length, "chunked")) {
else if (SW_STRCASEEQ(header_name, header_len, "transfer-encoding") && SW_STR_ISTARTS_WITH(at, length, "chunked")) {
ctx->recv_chunked = 1;
}

Expand All @@ -402,24 +401,27 @@ static int http_request_on_header_value(swoole_http_parser *parser, const char *
/**
* some common request header key
*/
if (SW_STREQ(header_name, header_len, "host")) {
if (SW_STRCASEEQ(header_name, header_len, "host")) {
zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_HOST), &tmp);
} else if (SW_STREQ(header_name, header_len, "user-agent")) {
} else if (SW_STRCASEEQ(header_name, header_len, "user-agent")) {
zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_USER_AGENT), &tmp);
} else if (SW_STREQ(header_name, header_len, "accept")) {
} else if (SW_STRCASEEQ(header_name, header_len, "accept")) {
zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_ACCEPT), &tmp);
} else if (SW_STREQ(header_name, header_len, "content-type")) {
} else if (SW_STRCASEEQ(header_name, header_len, "content-type")) {
zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_CONTENT_TYPE), &tmp);
} else if (SW_STREQ(header_name, header_len, "content-length")) {
} else if (SW_STRCASEEQ(header_name, header_len, "content-length")) {
zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_CONTENT_LENGTH), &tmp);
} else if (SW_STREQ(header_name, header_len, "authorization")) {
} else if (SW_STRCASEEQ(header_name, header_len, "authorization")) {
zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_AUTHORIZATION), &tmp);
} else if (SW_STREQ(header_name, header_len, "connection")) {
} else if (SW_STRCASEEQ(header_name, header_len, "connection")) {
zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_CONNECTION), &tmp);
} else if (SW_STREQ(header_name, header_len, "accept-encoding")) {
} else if (SW_STRCASEEQ(header_name, header_len, "accept-encoding")) {
zend_hash_update(Z_ARR_P(zheader), SW_ZSTR_KNOWN(SW_ZEND_STR_ACCEPT_ENCODING), &tmp);
} else {
zend_hash_str_update(Z_ARR_P(zheader), header_name, header_len, &tmp);
char *new_header_name = estrndup(header_name, header_len);
zend_str_tolower_copy(new_header_name, header_name, header_len);
zend_hash_str_update(Z_ARR_P(zheader), new_header_name, header_len, &tmp);
efree(new_header_name);
}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions ext-src/swoole_odbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ int php_swoole_odbc_minit(int module_id) {
if (zend_hash_str_find(&php_pdo_get_dbh_ce()->constants_table, ZEND_STRL("ODBC_ATTR_USE_CURSOR_LIBRARY")) ==
nullptr) {
#ifdef SQL_ATTR_CONNECTION_POOLING
char *pooling_val = NULL;
const char *pooling_val = NULL;
#endif

#ifdef SQL_ATTR_CONNECTION_POOLING
Expand All @@ -214,7 +214,7 @@ int php_swoole_odbc_minit(int module_id) {
* request without affecting others, which goes against our isolated request
* policy. So, we use cfg_get_string here to check it this once.
* */
if (FAILURE == cfg_get_string("pdo_odbc.connection_pooling", &pooling_val) || pooling_val == NULL) {
if (FAILURE == cfg_get_string("pdo_odbc.connection_pooling", (char **) &pooling_val) || pooling_val == NULL) {
pooling_val = "strict";
}
if (strcasecmp(pooling_val, "strict") == 0 || strcmp(pooling_val, "1") == 0) {
Expand Down
Loading
Loading