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 3fd2672 commit d239dda
Show file tree
Hide file tree
Showing 22 changed files with 4,559 additions and 660 deletions.
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', '8.4']
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', '8.4']
php: ['8.0', '8.1', '8.2', '8.3', '8.4-dev']

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

Expand Down
3 changes: 3 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,8 @@ 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 \
Expand Down Expand Up @@ -1241,6 +1243,7 @@ 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)
if test "$PHP_NGHTTP2_DIR" = "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/nghttp2)
fi
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/swoole_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@

#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
2 changes: 1 addition & 1 deletion src/core/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void Logger::put(int level, const char *content, size_t length) {
if (opened && flock(log_fd, LOCK_EX) == -1) {
return;
}
write(log_fd, log_str, n);
(void)write(log_fd, log_str, n);
if (opened && flock(log_fd, LOCK_UN) == -1) {
return;
}
Expand Down
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
60 changes: 60 additions & 0 deletions tests/swoole_http_server/exit.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--TEST--
swoole_http_server: exit
--SKIPIF--
<?php
if (PHP_VERSION_ID < 80400) {
require __DIR__ . '/../include/skipif.inc';
skip('php version 8.4 or higher');
}
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';

$pm = new ProcessManager;
$pm->parentFunc = function () use ($pm) {
Co\run(function () use ($pm) {
$uri = "http://127.0.0.1:{$pm->getFreePort()}";
httpRequest($uri);
});

$pm->kill();
echo "DONE\n";
};

$pm->childFunc = function () use ($pm) {
$http = new Swoole\Http\Server('127.0.0.1', $pm->getFreePort(), SWOOLE_BASE);
$http->on('workerStart', function () use ($pm) {
$pm->wakeup();
});

$http->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) use ($pm) {
try {
exit('Swoole Server exit test');
} catch (\Exception $e) {
echo $e->getMessage().PHP_EOL;
}

try {
exit();
} catch (\Exception $e) {
echo $e->getMessage().PHP_EOL;
}

try {
exit(400);
} catch (\Exception $e) {
echo $e->getStatus().PHP_EOL;
}
$response->end('Hello World');
});
$http->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--
Swoole Server exit test
swoole exit
400
DONE
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
2 changes: 1 addition & 1 deletion thirdparty/php/curl/curl_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "php_swoole_cxx.h"

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

#include <curl/curl.h>
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/php/curl/curl_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/* Copied from PHP-4f68662f5b61aecf90f6d8005976f5f91d4ce8d3 */

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

#ifndef _PHP_CURL_PRIVATE_H
#define _PHP_CURL_PRIVATE_H
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/php/curl/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "php_swoole_cxx.h"

#ifdef SW_USE_CURL
#if defined(SW_USE_CURL) && PHP_VERSION_ID < 80400
#include "php_swoole_curl.h"

using namespace swoole;
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/php/curl/multi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "php_swoole_cxx.h"
#include "zend_object_handlers.h"

#ifdef SW_USE_CURL
#if defined(SW_USE_CURL) && PHP_VERSION_ID < 80400
#include "php_swoole_curl.h"

using swoole::curl::Multi;
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/php/curl/php_curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/* Copied from PHP-7.4.11 */

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

#ifndef _PHP_CURL_H
#define _PHP_CURL_H
Expand Down
162 changes: 162 additions & 0 deletions thirdparty/php84/curl/curl_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: ddfcdd8a0bf0ee6c338ec1689c6de5d7fd87303d */
#include "curl_interface.h"

#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)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_swoole_native_curl_copy_handle, 0, 1, CurlHandle, MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_errno, 0, 1, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_error, 0, 1, IS_STRING, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_swoole_native_curl_escape, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
ZEND_END_ARG_INFO()

#define arginfo_swoole_native_curl_unescape arginfo_swoole_native_curl_escape

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_multi_setopt, 0, 3, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_swoole_native_curl_exec, 0, 1, MAY_BE_STRING|MAY_BE_BOOL)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
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")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_swoole_native_curl_init, 0, 0, CurlHandle, MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, url, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()

#if LIBCURL_VERSION_NUM >= 0x073E00 /* Available since 7.62.0 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_upkeep, 0, 1, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()
#endif

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_multi_add_handle, 0, 2, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_multi_close, 0, 1, IS_VOID, 0)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_multi_errno, 0, 1, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_multi_exec, 0, 2, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_ARG_INFO(1, still_running)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_multi_getcontent, 0, 1, IS_STRING, 1)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_swoole_native_curl_multi_info_read, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, queued_messages, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_swoole_native_curl_multi_init, 0, 0, CurlMultiHandle, 0)
ZEND_END_ARG_INFO()

#define arginfo_swoole_native_curl_multi_remove_handle arginfo_swoole_native_curl_multi_add_handle

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_multi_select, 0, 1, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, multi_handle, CurlMultiHandle, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timeout, IS_DOUBLE, 0, "1.0")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_multi_strerror, 0, 1, IS_STRING, 1)
ZEND_ARG_TYPE_INFO(0, error_code, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_pause, 0, 2, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
ZEND_END_ARG_INFO()

#define arginfo_swoole_native_curl_reset arginfo_swoole_native_curl_close

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_setopt_array, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_ARG_TYPE_INFO(0, options, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_swoole_native_curl_setopt, 0, 3, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, handle, CurlHandle, 0)
ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
ZEND_END_ARG_INFO()

#define arginfo_swoole_native_curl_strerror arginfo_swoole_native_curl_multi_strerror

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_swoole_native_curl_version, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_END_ARG_INFO()

static const zend_function_entry swoole_native_curl_functions[] = {
ZEND_FE(swoole_native_curl_close, arginfo_swoole_native_curl_close)
ZEND_FE(swoole_native_curl_copy_handle, arginfo_swoole_native_curl_copy_handle)
ZEND_FE(swoole_native_curl_errno, arginfo_swoole_native_curl_errno)
ZEND_FE(swoole_native_curl_error, arginfo_swoole_native_curl_error)
ZEND_FE(swoole_native_curl_escape, arginfo_swoole_native_curl_escape)
ZEND_FE(swoole_native_curl_unescape, arginfo_swoole_native_curl_unescape)
ZEND_FE(swoole_native_curl_multi_setopt, arginfo_swoole_native_curl_multi_setopt)
ZEND_FE(swoole_native_curl_exec, arginfo_swoole_native_curl_exec)
ZEND_FE(swoole_native_curl_getinfo, arginfo_swoole_native_curl_getinfo)
ZEND_FE(swoole_native_curl_init, arginfo_swoole_native_curl_init)
#if LIBCURL_VERSION_NUM >= 0x073E00 /* Available since 7.62.0 */
ZEND_FE(swoole_native_curl_upkeep, arginfo_swoole_native_curl_upkeep)
#endif
ZEND_FE(swoole_native_curl_multi_add_handle, arginfo_swoole_native_curl_multi_add_handle)
ZEND_FE(swoole_native_curl_multi_close, arginfo_swoole_native_curl_multi_close)
ZEND_FE(swoole_native_curl_multi_errno, arginfo_swoole_native_curl_multi_errno)
ZEND_FE(swoole_native_curl_multi_exec, arginfo_swoole_native_curl_multi_exec)
ZEND_FE(swoole_native_curl_multi_getcontent, arginfo_swoole_native_curl_multi_getcontent)
ZEND_FE(swoole_native_curl_multi_info_read, arginfo_swoole_native_curl_multi_info_read)
ZEND_FE(swoole_native_curl_multi_init, arginfo_swoole_native_curl_multi_init)
ZEND_FE(swoole_native_curl_multi_remove_handle, arginfo_swoole_native_curl_multi_remove_handle)
ZEND_FE(swoole_native_curl_multi_select, arginfo_swoole_native_curl_multi_select)
ZEND_FE(swoole_native_curl_multi_strerror, arginfo_swoole_native_curl_multi_strerror)
ZEND_FE(swoole_native_curl_pause, arginfo_swoole_native_curl_pause)
ZEND_FE(swoole_native_curl_reset, arginfo_swoole_native_curl_reset)
ZEND_FE(swoole_native_curl_setopt_array, arginfo_swoole_native_curl_setopt_array)
ZEND_FE(swoole_native_curl_setopt, arginfo_swoole_native_curl_setopt)
ZEND_FE(swoole_native_curl_strerror, arginfo_swoole_native_curl_strerror)
ZEND_FE(swoole_native_curl_version, arginfo_swoole_native_curl_version)
ZEND_FE_END
};

static const zend_function_entry class_CurlHandle_methods[] = {
ZEND_FE_END
};

static const zend_function_entry class_CurlMultiHandle_methods[] = {
ZEND_FE_END
};

static const zend_function_entry class_CurlShareHandle_methods[] = {
ZEND_FE_END
};
#endif
Loading

0 comments on commit d239dda

Please sign in to comment.