Skip to content

Commit

Permalink
Compatible with PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFreeman committed Aug 28, 2024
1 parent d14d6a2 commit 913d153
Show file tree
Hide file tree
Showing 52 changed files with 12,626 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ '8.0', '8.1', '8.2', '8.3' ]
php-version: [ '8.0', '8.1', '8.2', '8.3', '8.4' ]
framework: [ 'Laravel Octane', 'Hyperf', 'Simps', 'imi' ]
name: ${{ matrix.framework }} - PHP ${{ matrix.php-version }}
steps:
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ '8.0', '8.1', '8.2', '8.3' ]
php-version: [ '8.0', '8.1', '8.2', '8.3', '8.4' ]
framework: [ 'Simps' ]
name: ${{ matrix.framework }} - PHP ${{ matrix.php-version }} - macOS
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.0', '8.1', '8.2', '8.3']
php: ['8.0', '8.1', '8.2', '8.3', '8.4-dev']
steps:
- uses: actions/checkout@v4
- name: Setup PHP
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/xdebug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.0', '8.1', '8.2', '8.3']
php: ['8.0', '8.1', '8.2', '8.3', '8.4-dev']

name: PHP ${{ matrix.php }} - Swoole

Expand Down
27 changes: 22 additions & 5 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -1014,12 +1014,15 @@ EOF
swoole_source_file="$swoole_source_file \
thirdparty/php/curl/interface.cc \
thirdparty/php/curl/multi.cc \
thirdparty/php84/curl/interface.cc \
thirdparty/php84/curl/multi.cc \
thirdparty/php/sockets/multicast.cc \
thirdparty/php/sockets/sendrecvmsg.cc \
thirdparty/php/sockets/conversions.cc \
thirdparty/php/sockets/sockaddr_conv.cc \
thirdparty/php/standard/var_decoder.cc \
thirdparty/php/standard/proc_open.cc"
thirdparty/php/standard/proc_open.cc \
thirdparty/php84/hash/hash_sha.c "

swoole_source_file="$swoole_source_file \
thirdparty/swoole_http_parser.c \
Expand Down Expand Up @@ -1051,7 +1054,9 @@ EOF
thirdparty/php81/pdo_pgsql/pgsql_driver.c \
thirdparty/php81/pdo_pgsql/pgsql_statement.c \
thirdparty/php83/pdo_pgsql/pgsql_driver.c \
thirdparty/php83/pdo_pgsql/pgsql_statement.c"
thirdparty/php83/pdo_pgsql/pgsql_statement.c \
thirdparty/php84/pdo_pgsql/pgsql_driver.c \
thirdparty/php84/pdo_pgsql/pgsql_statement.c"
fi

if test "$PHP_SWOOLE_ORACLE" != "no"; then
Expand All @@ -1061,7 +1066,9 @@ EOF
thirdparty/php81/pdo_oci/oci_driver.c \
thirdparty/php81/pdo_oci/oci_statement.c \
thirdparty/php83/pdo_oci/oci_driver.c \
thirdparty/php83/pdo_oci/oci_statement.c"
thirdparty/php83/pdo_oci/oci_statement.c \
thirdparty/php84/pdo_oci/oci_driver.c \
thirdparty/php84/pdo_oci/oci_statement.c"
fi

if test "$PHP_SWOOLE_ODBC" != "no"; then
Expand All @@ -1071,7 +1078,9 @@ EOF
thirdparty/php81/pdo_odbc/odbc_driver.c \
thirdparty/php81/pdo_odbc/odbc_stmt.c \
thirdparty/php83/pdo_odbc/odbc_driver.c \
thirdparty/php83/pdo_odbc/odbc_stmt.c"
thirdparty/php83/pdo_odbc/odbc_stmt.c \
thirdparty/php84/pdo_odbc/odbc_driver.c \
thirdparty/php84/pdo_odbc/odbc_stmt.c"
fi

if test "$PHP_SWOOLE_SQLITE" != "no"; then
Expand All @@ -1081,7 +1090,9 @@ EOF
thirdparty/php81/pdo_sqlite/sqlite_driver.c \
thirdparty/php81/pdo_sqlite/sqlite_statement.c \
thirdparty/php83/pdo_sqlite/sqlite_driver.c \
thirdparty/php83/pdo_sqlite/sqlite_statement.c"
thirdparty/php83/pdo_sqlite/sqlite_statement.c \
thirdparty/php84/pdo_sqlite/sqlite_driver.c \
thirdparty/php84/pdo_sqlite/sqlite_statement.c"
fi

SW_ASM_DIR="thirdparty/boost/asm/"
Expand Down Expand Up @@ -1232,27 +1243,33 @@ EOF
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php/sockets)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php/standard)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php/curl)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php84/curl)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php84/hash)
if test "$PHP_NGHTTP2_DIR" = "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/nghttp2)
fi
if test "$PHP_SWOOLE_PGSQL" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php80/pdo_pgsql)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php81/pdo_pgsql)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php83/pdo_pgsql)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php84/pdo_pgsql)
fi
if test "$PHP_SWOOLE_ODBC" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php80/pdo_odbc)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php81/pdo_odbc)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php83/pdo_odbc)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php84/pdo_odbc)
fi
if test "$PHP_SWOOLE_ORACLE" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php80/pdo_oci)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php81/pdo_oci)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php83/pdo_oci)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php84/pdo_oci)
fi
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)
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php84/pdo_sqlite)
fi
fi
1 change: 1 addition & 0 deletions ext-src/php_swoole_coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#define SW_DEFAULT_MAX_CORO_NUM 100000
#define SW_DEFAULT_PHP_STACK_PAGE_SIZE 8192
enum sw_exit_flags { SW_EXIT_IN_COROUTINE = 1 << 1, SW_EXIT_IN_SERVER = 1 << 2 };

#define SWOG ((zend_output_globals *) &OG(handlers))

Expand Down
6 changes: 6 additions & 0 deletions ext-src/php_swoole_curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
SW_EXTERN_C_BEGIN
#include <curl/curl.h>
#include <curl/multi.h>
#ifdef SW_USE_CURL
#if PHP_VERSION_ID >= 80400
#include "thirdparty/php84/curl/curl_private.h"
#else
#include "thirdparty/php/curl/curl_private.h"
#endif
#endif
SW_EXTERN_C_END

#if LIBCURL_VERSION_NUM < 0x073800
Expand Down
4 changes: 4 additions & 0 deletions ext-src/php_swoole_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ extern zend_object_handlers swoole_exception_handlers;
extern zend_class_entry *swoole_error_ce;
extern zend_class_entry *swoole_resolve_context_ce;
extern zend_object_handlers swoole_resolve_context_handlers;
#if PHP_VERSION_ID >= 80400
extern zend_class_entry *swoole_exit_exception_ce;
extern zend_object_handlers swoole_exit_exception_handlers;
#endif

PHP_FUNCTION(swoole_clear_dns_cache);
PHP_FUNCTION(swoole_last_error);
Expand Down
22 changes: 17 additions & 5 deletions ext-src/swoole_coroutine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include "php_swoole_cxx.h"
#include "php_swoole_coroutine_system.h"

#if PHP_VERSION_ID < 80400
#include "swoole_server.h"
#endif
#include "swoole_signal.h"

#include "zend_builtin_functions.h"
Expand Down Expand Up @@ -55,8 +57,6 @@ static zend_always_inline zend_vm_stack zend_vm_stack_new_page(size_t size, zend
}
#endif

enum sw_exit_flags { SW_EXIT_IN_COROUTINE = 1 << 1, SW_EXIT_IN_SERVER = 1 << 2 };

bool PHPCoroutine::activated = false;
zend_array *PHPCoroutine::options = nullptr;

Expand All @@ -73,19 +73,27 @@ bool PHPCoroutine::interrupt_thread_running = false;

extern void php_swoole_load_library();

static zend_atomic_bool *zend_vm_interrupt = nullptr;
#if PHP_VERSION_ID < 80400
static user_opcode_handler_t ori_exit_handler = nullptr;
#endif

static zend_atomic_bool *zend_vm_interrupt = nullptr;
static user_opcode_handler_t ori_begin_silence_handler = nullptr;
static user_opcode_handler_t ori_end_silence_handler = nullptr;
static unordered_map<long, Coroutine *> user_yield_coros;

static void (*orig_interrupt_function)(zend_execute_data *execute_data) = nullptr;

static zend_class_entry *swoole_coroutine_util_ce;
static zend_class_entry *swoole_exit_exception_ce;
static zend_object_handlers swoole_exit_exception_handlers;
static zend_class_entry *swoole_coroutine_iterator_ce;
static zend_class_entry *swoole_coroutine_context_ce;
#if PHP_VERSION_ID >= 80400
zend_class_entry *swoole_exit_exception_ce;
zend_object_handlers swoole_exit_exception_handlers;
#else
static zend_class_entry *swoole_exit_exception_ce;
static zend_object_handlers swoole_exit_exception_handlers;
#endif

SW_EXTERN_C_BEGIN
static PHP_METHOD(swoole_coroutine, exists);
Expand Down Expand Up @@ -180,6 +188,7 @@ static const zend_function_entry swoole_exit_exception_methods[] = {
};
// clang-format on

#if PHP_VERSION_ID < 80400
static int coro_exit_handler(zend_execute_data *execute_data) {
zval ex;
zend_object *obj;
Expand Down Expand Up @@ -224,6 +233,7 @@ static int coro_exit_handler(zend_execute_data *execute_data) {

return ZEND_USER_OPCODE_DISPATCH;
}
#endif

static int coro_begin_silence_handler(zend_execute_data *execute_data) {
PHPContext *task = PHPCoroutine::get_context();
Expand Down Expand Up @@ -989,8 +999,10 @@ void php_swoole_coroutine_minit(int module_number) {

void php_swoole_coroutine_rinit() {
if (SWOOLE_G(cli)) {
#if PHP_VERSION_ID < 80400
ori_exit_handler = zend_get_user_opcode_handler(ZEND_EXIT);
zend_set_user_opcode_handler(ZEND_EXIT, coro_exit_handler);
#endif

ori_begin_silence_handler = zend_get_user_opcode_handler(ZEND_BEGIN_SILENCE);
zend_set_user_opcode_handler(ZEND_BEGIN_SILENCE, coro_begin_silence_handler);
Expand Down
6 changes: 6 additions & 0 deletions ext-src/swoole_mysql_coro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@
#undef L64

SW_EXTERN_C_BEGIN

#if PHP_VERSION_ID >= 80400
#include "thirdparty/php84/hash/php_hash.h"
#include "thirdparty/php84/hash/php_hash_sha.h"
#else
#include "ext/hash/php_hash.h"
#include "ext/hash/php_hash_sha.h"
#endif
#include "ext/standard/php_math.h"
#ifdef SW_USE_MYSQLND
#include "ext/mysqlnd/mysqlnd.h"
Expand Down
59 changes: 59 additions & 0 deletions ext-src/swoole_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@
#include "swoole_socket.h"
#include "swoole_util.h"

#if PHP_VERSION_ID >= 80400
#include "swoole_server.h"
#endif

#include "thirdparty/php/standard/proc_open.h"
#ifdef SW_USE_CURL
#if PHP_VERSION_ID >= 80400
#include "thirdparty/php84/curl/curl_interface.h"
#else
#include "thirdparty/php/curl/curl_interface.h"
#endif
#endif

#include <unordered_map>

Expand Down Expand Up @@ -76,6 +84,9 @@ static PHP_FUNCTION(swoole_time_sleep_until);
static PHP_FUNCTION(swoole_stream_select);
static PHP_FUNCTION(swoole_stream_socket_pair);
static PHP_FUNCTION(swoole_user_func_handler);
#if PHP_VERSION_ID >= 80400
static PHP_FUNCTION(swoole_exit);
#endif
SW_EXTERN_C_END

static void inherit_class(const char *child_name, size_t child_length, const char *parent_name, size_t parent_length);
Expand Down Expand Up @@ -233,6 +244,9 @@ struct real_func {
void php_swoole_runtime_rinit() {
tmp_function_table = (zend_array *) emalloc(sizeof(zend_array));
zend_hash_init(tmp_function_table, 8, nullptr, nullptr, 0);
#if PHP_VERSION_ID >= 80400
SW_HOOK_FUNC(exit);
#endif
}

void php_swoole_runtime_rshutdown() {
Expand Down Expand Up @@ -2120,3 +2134,48 @@ static void clear_class_entries() {
}
child_class_entries.clear();
}

#if PHP_VERSION_ID >= 80400
static PHP_FUNCTION(swoole_exit) {
zend_string *message = NULL;
zend_long status = 0;

ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_STR_OR_LONG(message, status)
ZEND_PARSE_PARAMETERS_END();

zend_long flags = 0;
if (Coroutine::get_current()) {
flags |= SW_EXIT_IN_COROUTINE;
}

if (sw_server() && sw_server()->is_started()) {
flags |= SW_EXIT_IN_SERVER;
}

if (flags) {
zval ex = {};
zend_object *obj = zend_throw_exception(swoole_exit_exception_ce, (message ? ZSTR_VAL(message) : "swoole exit"), 0);
ZVAL_OBJ(&ex, obj);
zend_update_property_long(swoole_exit_exception_ce, SW_Z8_OBJ_P(&ex), ZEND_STRL("flags"), flags);
zend_update_property_long(swoole_exit_exception_ce, SW_Z8_OBJ_P(&ex), ZEND_STRL("status"), status);
} else {
if (message) {
size_t len = ZSTR_LEN(message);
if (len != 0) {
/* An exception might be emitted by an output handler */
zend_write(ZSTR_VAL(message), len);
if (EG(exception)) {
RETURN_THROWS();
}
}
} else {
EG(exit_status) = status;
}

ZEND_ASSERT(!EG(exception));
zend_throw_unwind_exit();
}
}
#endif
6 changes: 3 additions & 3 deletions tests/include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ function get_big_random(int $length = 1024 * 1024)
return str_repeat(get_safe_random(1024), $length / 1024);
}

function makeCoTcpClient($host, $port, callable $onConnect = null, callable $onReceive = null)
function makeCoTcpClient($host, $port, ?callable $onConnect = null, ?callable $onReceive = null)
{
go(function () use ($host, $port, $onConnect, $onReceive) {
$cli = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP);
Expand Down Expand Up @@ -457,7 +457,7 @@ function killself_in_syncmode($lifetime = 1000, $sig = SIGKILL)
* @param callable $cb
* @return mixed
*/
function suicide($lifetime, $sig = SIGKILL, callable $cb = null)
function suicide($lifetime, $sig = SIGKILL, ?callable $cb = null)
{
return Swoole\Timer::after($lifetime, function () use ($lifetime, $sig, $cb) {
if ($cb) {
Expand Down Expand Up @@ -676,7 +676,7 @@ function php_fork_exec(callable $fn, $f_stdout = "/dev/null", $f_stderr = null)
* @param array|null $env env
* @return array [out, err]
*/
function spawn_exec($cmd, $input = null, $tv_sec = null, $tv_usec = null, $cwd = null, array $env = null)
function spawn_exec($cmd, $input = null, $tv_sec = null, $tv_usec = null, $cwd = null, ?array $env = null)
{
$out = $err = null;
$winOpt = ['suppress_errors' => true, 'binary_pipes' => true];
Expand Down
8 changes: 1 addition & 7 deletions thirdparty/php/curl/curl_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "curl_interface.h"

#ifdef SW_USE_CURL
#if defined(SW_USE_CURL) && PHP_VERSION_ID < 80400

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_close, 0, 1, IS_VOID, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
Expand Down Expand Up @@ -32,12 +32,6 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_swoole_native_curl_exec, 0, 1, M
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_swoole_native_curl_file_create, 0, 1, CURLFile, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mime_type, IS_STRING, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, posted_filename, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_getinfo, 0, 1, IS_MIXED, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, option, IS_LONG, 1, "null")
Expand Down
Loading

0 comments on commit 913d153

Please sign in to comment.