From ec2a79ee94daa89ec634c9659aa7c2a6848cadc4 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 16 Sep 2022 14:13:38 +0200 Subject: add upstream patches for PHP 8.2 --- openswoole-php82.patch | 677 +++++++++++++++++++++++++++++++++++++++++++++++ php-pecl-openswoole.spec | 25 +- 2 files changed, 691 insertions(+), 11 deletions(-) create mode 100644 openswoole-php82.patch diff --git a/openswoole-php82.patch b/openswoole-php82.patch new file mode 100644 index 0000000..3c59005 --- /dev/null +++ b/openswoole-php82.patch @@ -0,0 +1,677 @@ +diff --git a/ext-src/php_swoole.cc b/ext-src/php_swoole.cc +index 2ee5f4054..dcfc775e4 100644 +--- a/ext-src/php_swoole.cc ++++ b/ext-src/php_swoole.cc +@@ -389,6 +389,9 @@ void php_swoole_set_global_option(HashTable *vht) { + if (php_swoole_array_get_value(vht, "max_concurrency", ztmp)) { + SwooleG.max_concurrency = (uint32_t) SW_MAX(0, zval_get_long(ztmp)); + } ++ if (php_swoole_array_get_value(vht, "enable_server_token", ztmp) && zval_is_true(ztmp)) { ++ SwooleG.enable_server_token = zval_is_true(ztmp); ++ } + } + + void php_swoole_register_rshutdown_callback(swoole::Callback cb, void *private_data) { +diff --git a/ext-src/php_swoole_cxx.cc b/ext-src/php_swoole_cxx.cc +index 3a08191e8..8ae0be5c5 100644 +--- a/ext-src/php_swoole_cxx.cc ++++ b/ext-src/php_swoole_cxx.cc +@@ -18,6 +18,7 @@ typedef zval zend_source_string_t; + typedef zend_string zend_source_string_t; + #endif + ++#if PHP_VERSION_ID < 80200 + static zend_op_array *swoole_compile_string(zend_source_string_t *source_string, ZEND_STR_CONST char *filename); + + // for compatibly with dis_eval +@@ -28,6 +29,18 @@ static zend_op_array *swoole_compile_string(zend_source_string_t *source_string, + opa->type = ZEND_USER_FUNCTION; + return opa; + } ++#else ++static zend_op_array *swoole_compile_string(zend_source_string_t *source_string, ZEND_STR_CONST char *filename, zend_compile_position position); ++ ++static zend_op_array *(*old_compile_string)(zend_source_string_t *source_string, ZEND_STR_CONST char *filename, zend_compile_position position); ++ ++static zend_op_array *swoole_compile_string(zend_source_string_t *source_string, ZEND_STR_CONST char *filename, zend_compile_position position) { ++ zend_op_array *opa = old_compile_string(source_string, filename, position); ++ opa->type = ZEND_USER_FUNCTION; ++ return opa; ++} ++#endif ++ + + namespace zend { + bool eval(const std::string &code, std::string const &filename) { +diff --git a/ext-src/php_swoole_library.h b/ext-src/php_swoole_library.h +index 892f795eb..a632c9f4e 100644 +--- a/ext-src/php_swoole_library.h ++++ b/ext-src/php_swoole_library.h +@@ -2,7 +2,7 @@ + * Generated by build-library.php, Please DO NOT modify! + */ + +-/* $Id: f9f606fb95652b0c1adfc2011513808185152568 */ ++/* $Id: 19668965fb5df74d799cefa05913535916135160 */ + + static const char* swoole_library_source_constants = + "\n" +@@ -172,6 +172,8 @@ static const char* swoole_library_source_core_constant = + "\n" + " public const OPTION_MAX_CONCURRENCY = 'max_concurrency';\n" + "\n" ++ " public const OPTION_ENABLE_SERVER_TOKEN = 'enable_server_token';\n" ++ "\n" + " public const OPTION_AIO_CORE_WORKER_NUM = 'aio_core_worker_num';\n" + "\n" + " public const OPTION_AIO_WORKER_NUM = 'aio_worker_num';\n" +@@ -888,12 +890,18 @@ static const char* swoole_library_source_core_array_object = + " return count($this->array);\n" + " }\n" + "\n" ++ " /**\n" ++ " * @return mixed\n" ++ " */\n" + " #[\\ReturnTypeWillChange]\n" + " public function current()\n" + " {\n" + " return current($this->array);\n" + " }\n" + "\n" ++ " /**\n" ++ " * @return mixed\n" ++ " */\n" + " #[\\ReturnTypeWillChange]\n" + " public function key()\n" + " {\n" +@@ -1065,6 +1073,7 @@ static const char* swoole_library_source_core_array_object = + " /**\n" + " * @param mixed $key\n" + " * @param mixed $offset\n" ++ " * @return bool\n" + " */\n" + " #[\\ReturnTypeWillChange]\n" + " public function offsetExists($offset)\n" +@@ -3937,17 +3946,17 @@ static const char* swoole_library_source_core_curl_handler = + " case CURLOPT_PRIVATE:\n" + " $this->info['private'] = $value;\n" + " break;\n" +- " /*\n" +- " * Ignore options\n" +- " */\n" ++ " /*\n" ++ " * Ignore options\n" ++ " */\n" + " case CURLOPT_VERBOSE:\n" + " // trigger_error('swoole_curl_setopt(): CURLOPT_VERBOSE is not supported', E_USER_WARNING);\n" + " case CURLOPT_SSLVERSION:\n" + " case CURLOPT_NOSIGNAL:\n" + " case CURLOPT_FRESH_CONNECT:\n" +- " /*\n" +- " * From PHP 5.1.3, this option has no effect: the raw output will always be returned when CURLOPT_RETURNTRANSFER is used.\n" +- " */\n" ++ " /*\n" ++ " * From PHP 5.1.3, this option has no effect: the raw output will always be returned when CURLOPT_RETURNTRANSFER is used.\n" ++ " */\n" + " case CURLOPT_BINARYTRANSFER: /* TODO */\n" + " case CURLOPT_DNS_USE_GLOBAL_CACHE:\n" + " case CURLOPT_DNS_CACHE_TIMEOUT:\n" +@@ -3961,9 +3970,9 @@ static const char* swoole_library_source_core_curl_handler = + " case CURLOPT_HEADEROPT:\n" + " case CURLOPT_PROXYHEADER:\n" + " break;\n" +- " /*\n" +- " * SSL\n" +- " */\n" ++ " /*\n" ++ " * SSL\n" ++ " */\n" + " case CURLOPT_SSL_VERIFYHOST:\n" + " break;\n" + " case CURLOPT_SSL_VERIFYPEER:\n" +@@ -3986,9 +3995,9 @@ static const char* swoole_library_source_core_curl_handler = + " case CURLOPT_SSLKEYPASSWD:\n" + " $this->clientOptions[Constant::OPTION_SSL_PASSPHRASE] = $value;\n" + " break;\n" +- " /*\n" +- " * Http POST\n" +- " */\n" ++ " /*\n" ++ " * Http POST\n" ++ " */\n" + " case CURLOPT_POST:\n" + " $this->method = 'POST';\n" + " break;\n" +@@ -3998,18 +4007,18 @@ static const char* swoole_library_source_core_curl_handler = + " $this->method = 'POST';\n" + " }\n" + " break;\n" +- " /*\n" +- " * Upload\n" +- " */\n" ++ " /*\n" ++ " * Upload\n" ++ " */\n" + " case CURLOPT_SAFE_UPLOAD:\n" + " if (!$value) {\n" + " trigger_error('swoole_curl_setopt(): Disabling safe uploads is no longer supported', E_USER_WARNING);\n" + " return false;\n" + " }\n" + " break;\n" +- " /*\n" +- " * Http Header\n" +- " */\n" ++ " /*\n" ++ " * Http Header\n" ++ " */\n" + " case CURLOPT_HTTPHEADER:\n" + " if (!is_array($value) and !is_iterable($value)) {\n" + " trigger_error('swoole_curl_setopt(): You must pass either an object or an array with the CURLOPT_HTTPHEADER argument', E_USER_WARNING);\n" +@@ -4056,9 +4065,9 @@ static const char* swoole_library_source_core_curl_handler = + " case CURLOPT_FAILONERROR:\n" + " $this->failOnError = $value;\n" + " break;\n" +- " /*\n" +- " * Http Cookie\n" +- " */\n" ++ " /*\n" ++ " * Http Cookie\n" ++ " */\n" + " case CURLOPT_COOKIE:\n" + " $this->setHeader('Cookie', $value);\n" + " break;\n" +@@ -5670,7 +5679,7 @@ static const char* swoole_library_source_core_fast_cgi_request = + " public function __toString(): string\n" + " {\n" + " $body = $this->getBody();\n" +- " $beginRequestFrame = new BeginRequest(FastCGI::RESPONDER, ($this->keepConn ? FastCGI::KEEP_CONN : 0));\n" ++ " $beginRequestFrame = new BeginRequest(FastCGI::RESPONDER, $this->keepConn ? FastCGI::KEEP_CONN : 0);\n" + " $paramsFrame = new Params($this->getParams());\n" + " $paramsEofFrame = new Params();\n" + " if (empty($body)) {\n" +@@ -6622,7 +6631,7 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_proxy = + " $server = $userRequest->server;\n" + " $headers = $userRequest->header;\n" + " $pathInfo = $userRequest->server['path_info'];\n" +- " $pathInfo = '/' . (ltrim($pathInfo, '/'));\n" ++ " $pathInfo = '/' . ltrim($pathInfo, '/');\n" + " if (strlen($this->index) !== 0) {\n" + " $extension = pathinfo($pathInfo, PATHINFO_EXTENSION);\n" + " if (empty($extension)) {\n" +@@ -6675,7 +6684,7 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_proxy = + "\n" + " public function pass($userRequest, $userResponse): void\n" + " {\n" +- " if (!($userRequest instanceof HttpRequest)) {\n" ++ " if (!$userRequest instanceof HttpRequest) {\n" + " $request = $this->translateRequest($userRequest);\n" + " } else {\n" + " $request = $userRequest;\n" +@@ -6727,6 +6736,7 @@ static const char* swoole_library_source_core_process_manager = + "namespace Swoole\\Process;\n" + "\n" + "use Swoole\\Constant;\n" ++ "\n" + "use function Swoole\\Coroutine\\run;\n" + "\n" + "class Manager\n" +@@ -6914,6 +6924,7 @@ static const char* swoole_library_source_core_server_helper = + " 'http2_max_concurrent_streams' => true,\n" + " 'http2_max_frame_size' => true,\n" + " 'http2_max_header_list_size' => true,\n" ++ " 'enable_server_token' => true,\n" + " ];\n" + "\n" + " public const PORT_OPTIONS = [\n" +@@ -6972,7 +6983,7 @@ static const char* swoole_library_source_core_server_helper = + "\n" + " foreach ($input_options as $k => $v) {\n" + " if (!array_key_exists(strtolower($k), $const_options)) {\n" +- " //TODO throw exception\n" ++ " // TODO throw exception\n" + " trigger_error(\"Unknown option [{$k}]\", E_USER_WARNING);\n" + " debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);\n" + " }\n" +@@ -7001,85 +7012,85 @@ static const char* swoole_library_source_core_server_helper = + " $event_workers = '';\n" + " $event_workers .= \"# TYPE openswoole_event_workers_start_time gauge\\n\";\n" + " foreach ($stats['event_workers'] as $stat) {\n" +- " $event_workers .= \"openswoole_event_workers_start_time{worker_id=\\\"{$stat['worker_id']}\\\"} ${stat['start_time']}\\n\";\n" ++ " $event_workers .= \"openswoole_event_workers_start_time{worker_id=\\\"{$stat['worker_id']}\\\"} {$stat['start_time']}\\n\";\n" + " }\n" + " $event_workers .= \"# TYPE openswoole_event_workers_start_seconds gauge\\n\";\n" + " foreach ($stats['event_workers'] as $stat) {\n" +- " $event_workers .= \"openswoole_event_workers_start_seconds{worker_id=\\\"{$stat['worker_id']}\\\"} ${stat['start_seconds']}\\n\";\n" ++ " $event_workers .= \"openswoole_event_workers_start_seconds{worker_id=\\\"{$stat['worker_id']}\\\"} {$stat['start_seconds']}\\n\";\n" + " }\n" + " $event_workers .= \"# TYPE openswoole_event_workers_dispatch_count gauge\\n\";\n" + " foreach ($stats['event_workers'] as $stat) {\n" +- " $event_workers .= \"openswoole_event_workers_dispatch_count{worker_id=\\\"{$stat['worker_id']}\\\"} ${stat['dispatch_count']}\\n\";\n" ++ " $event_workers .= \"openswoole_event_workers_dispatch_count{worker_id=\\\"{$stat['worker_id']}\\\"} {$stat['dispatch_count']}\\n\";\n" + " }\n" + " $event_workers .= \"# TYPE openswoole_event_workers_request_count gauge\\n\";\n" + " foreach ($stats['event_workers'] as $stat) {\n" +- " $event_workers .= \"openswoole_event_workers_request_count{worker_id=\\\"{$stat['worker_id']}\\\"} ${stat['request_count']}\\n\";\n" ++ " $event_workers .= \"openswoole_event_workers_request_count{worker_id=\\\"{$stat['worker_id']}\\\"} {$stat['request_count']}\\n\";\n" + " }\n" + "\n" + " $task_workers = '';\n" + " $task_workers .= \"# TYPE openswoole_task_workers_start_time gauge\\n\";\n" + " foreach ($stats['task_workers'] as $stat) {\n" +- " $task_workers .= \"openswoole_task_workers_start_time{worker_id=\\\"{$stat['worker_id']}\\\"} ${stat['start_time']}\\n\";\n" ++ " $task_workers .= \"openswoole_task_workers_start_time{worker_id=\\\"{$stat['worker_id']}\\\"} {$stat['start_time']}\\n\";\n" + " }\n" + " $task_workers .= \"# TYPE openswoole_task_workers_start_seconds gauge\\n\";\n" + " foreach ($stats['task_workers'] as $stat) {\n" +- " $task_workers .= \"openswoole_task_workers_start_seconds{worker_id=\\\"{$stat['worker_id']}\\\"} ${stat['start_seconds']}\\n\";\n" ++ " $task_workers .= \"openswoole_task_workers_start_seconds{worker_id=\\\"{$stat['worker_id']}\\\"} {$stat['start_seconds']}\\n\";\n" + " }\n" + "\n" + " $user_workers = '';\n" + " $user_workers .= \"# TYPE openswoole_user_workers_start_time gauge\\n\";\n" + " foreach ($stats['user_workers'] as $stat) {\n" +- " $user_workers .= \"openswoole_user_workers_start_time{worker_id=\\\"{$stat['worker_id']}\\\"} ${stat['start_time']}\\n\";\n" ++ " $user_workers .= \"openswoole_user_workers_start_time{worker_id=\\\"{$stat['worker_id']}\\\"} {$stat['start_time']}\\n\";\n" + " }\n" + " $user_workers .= \"# TYPE openswoole_user_workers_start_seconds gauge\\n\";\n" + " foreach ($stats['user_workers'] as $stat) {\n" +- " $user_workers .= \"openswoole_user_workers_start_seconds{worker_id=\\\"{$stat['worker_id']}\\\"} ${stat['start_seconds']}\\n\";\n" ++ " $user_workers .= \"openswoole_user_workers_start_seconds{worker_id=\\\"{$stat['worker_id']}\\\"} {$stat['start_seconds']}\\n\";\n" + " }\n" + "\n" + " return \"# TYPE openswoole_info gauge\\n\"\n" + " . \"openswoole_info{version=\\\"{$stats['version']}\\\"} 1\\n\"\n" + " . \"# TYPE openswoole_up gauge\\n\"\n" +- " . \"openswoole_up ${stats['up']}\\n\"\n" ++ " . \"openswoole_up {$stats['up']}\\n\"\n" + " . \"# TYPE openswoole_reactor_num gauge\\n\"\n" +- " . \"openswoole_reactor_threads_num ${stats['reactor_threads_num']}\\n\"\n" ++ " . \"openswoole_reactor_threads_num {$stats['reactor_threads_num']}\\n\"\n" + " . \"# TYPE openswoole_requests counter\\n\"\n" +- " . \"openswoole_requests_total ${stats['requests_total']}\\n\"\n" ++ " . \"openswoole_requests_total {$stats['requests_total']}\\n\"\n" + " . \"# TYPE openswoole_start_time gauge\\n\"\n" +- " . \"openswoole_start_time ${stats['start_time']}\\n\"\n" ++ " . \"openswoole_start_time {$stats['start_time']}\\n\"\n" + " . \"# TYPE openswoole_max_conn gauge\\n\"\n" +- " . \"openswoole_max_conn ${stats['max_conn']}\\n\"\n" ++ " . \"openswoole_max_conn {$stats['max_conn']}\\n\"\n" + " . \"# TYPE openswoole_coroutine_num gauge\\n\"\n" +- " . \"openswoole_coroutine_num ${stats['coroutine_num']}\\n\"\n" ++ " . \"openswoole_coroutine_num {$stats['coroutine_num']}\\n\"\n" + " . \"# TYPE openswoole_start_seconds gauge\\n\"\n" +- " . \"openswoole_start_seconds ${stats['start_seconds']}\\n\"\n" ++ " . \"openswoole_start_seconds {$stats['start_seconds']}\\n\"\n" + " . \"# TYPE openswoole_workers_total gauge\\n\"\n" +- " . \"openswoole_workers_total ${stats['workers_total']}\\n\"\n" ++ " . \"openswoole_workers_total {$stats['workers_total']}\\n\"\n" + " . \"# TYPE openswoole_workers_idle gauge\\n\"\n" +- " . \"openswoole_workers_idle ${stats['workers_idle']}\\n\"\n" ++ " . \"openswoole_workers_idle {$stats['workers_idle']}\\n\"\n" + " . \"# TYPE openswoole_task_workers_total gauge\\n\"\n" +- " . \"openswoole_task_workers_total ${stats['task_workers_total']}\\n\"\n" ++ " . \"openswoole_task_workers_total {$stats['task_workers_total']}\\n\"\n" + " . \"# TYPE openswoole_task_workers_idle gauge\\n\"\n" +- " . \"openswoole_task_workers_idle ${stats['task_workers_idle']}\\n\"\n" ++ " . \"openswoole_task_workers_idle {$stats['task_workers_idle']}\\n\"\n" + " . \"# TYPE openswoole_user_workers_total gauge\\n\"\n" +- " . \"openswoole_user_workers_total ${stats['user_workers_total']}\\n\"\n" ++ " . \"openswoole_user_workers_total {$stats['user_workers_total']}\\n\"\n" + " . \"# TYPE openswoole_dispatch_total gauge\\n\"\n" +- " . \"openswoole_dispatch_total ${stats['dispatch_total']}\\n\"\n" ++ " . \"openswoole_dispatch_total {$stats['dispatch_total']}\\n\"\n" + " . \"# TYPE openswoole_connections_accepted gauge\\n\"\n" +- " . \"openswoole_connections_accepted ${stats['connections_accepted']}\\n\"\n" ++ " . \"openswoole_connections_accepted {$stats['connections_accepted']}\\n\"\n" + " . \"# TYPE openswoole_connections_active gauge\\n\"\n" +- " . \"openswoole_connections_active ${stats['connections_active']}\\n\"\n" ++ " . \"openswoole_connections_active {$stats['connections_active']}\\n\"\n" + " . \"# TYPE openswoole_connections_closed gauge\\n\"\n" +- " . \"openswoole_connections_closed ${stats['connections_closed']}\\n\"\n" ++ " . \"openswoole_connections_closed {$stats['connections_closed']}\\n\"\n" + " . \"# TYPE openswoole_reload_count gauge\\n\"\n" +- " . \"openswoole_reload_count ${stats['reload_count']}\\n\"\n" ++ " . \"openswoole_reload_count {$stats['reload_count']}\\n\"\n" + " . \"# TYPE openswoole_reload_last_time gauge\\n\"\n" +- " . \"openswoole_reload_last_time ${stats['reload_last_time']}\\n\"\n" ++ " . \"openswoole_reload_last_time {$stats['reload_last_time']}\\n\"\n" + " . \"# TYPE openswoole_worker_vm_object_num gauge\\n\"\n" +- " . \"openswoole_worker_vm_object_num ${stats['worker_vm_object_num']}\\n\"\n" ++ " . \"openswoole_worker_vm_object_num {$stats['worker_vm_object_num']}\\n\"\n" + " . \"# TYPE openswoole_worker_vm_resource_num gauge\\n\"\n" +- " . \"openswoole_worker_vm_resource_num ${stats['worker_vm_resource_num']}\\n\"\n" ++ " . \"openswoole_worker_vm_resource_num {$stats['worker_vm_resource_num']}\\n\"\n" + " . \"# TYPE openswoole_worker_memory_usage gauge\\n\"\n" +- " . \"openswoole_worker_memory_usage ${stats['worker_memory_usage']}\\n{$event_workers}{$task_workers}{$user_workers}\"\n" ++ " . \"openswoole_worker_memory_usage {$stats['worker_memory_usage']}\\n{$event_workers}{$task_workers}{$user_workers}\"\n" + " . '# EOF';\n" + " }\n" + "}\n"; +@@ -7181,7 +7192,7 @@ static const char* swoole_library_source_core_coroutine_functions = + " echo Coroutine::printBackTrace($cid, DEBUG_BACKTRACE_IGNORE_ARGS, $depth);\n" + " echo \"\\n\";\n" + " $index++;\n" +- " //limit the number of maximum outputs\n" ++ " // limit the number of maximum outputs\n" + " if ($index >= $limit) {\n" + " break;\n" + " }\n" +@@ -7577,28 +7588,28 @@ static const char* swoole_library_source_functions = + " $type = $_f->get(1)->trim();\n" + "\n" + " switch ($type) {\n" +- " case 'i':\n" +- " case 'int':\n" +- " $table->column($name, Swoole\\Table::TYPE_INT);\n" +- " break;\n" +- " case 'f':\n" +- " case 'float':\n" +- " $table->column($name, Swoole\\Table::TYPE_FLOAT);\n" +- " break;\n" +- " case 's':\n" +- " case 'string':\n" +- " if ($_f->count() < 3) {\n" +- " throw new RuntimeException('need to give string length');\n" +- " }\n" +- " $length = intval($_f->get(2)->trim()->toString());\n" +- " if ($length <= 0) {\n" +- " throw new RuntimeException(\"invalid string length[{$length}]\");\n" +- " }\n" +- " $table->column($name, Swoole\\Table::TYPE_STRING, $length);\n" +- " break;\n" +- " default:\n" +- " throw new RuntimeException(\"unknown field type[{$type}]\");\n" +- " break;\n" ++ " case 'i':\n" ++ " case 'int':\n" ++ " $table->column($name, Swoole\\Table::TYPE_INT);\n" ++ " break;\n" ++ " case 'f':\n" ++ " case 'float':\n" ++ " $table->column($name, Swoole\\Table::TYPE_FLOAT);\n" ++ " break;\n" ++ " case 's':\n" ++ " case 'string':\n" ++ " if ($_f->count() < 3) {\n" ++ " throw new RuntimeException('need to give string length');\n" ++ " }\n" ++ " $length = intval($_f->get(2)->trim()->toString());\n" ++ " if ($length <= 0) {\n" ++ " throw new RuntimeException(\"invalid string length[{$length}]\");\n" ++ " }\n" ++ " $table->column($name, Swoole\\Table::TYPE_STRING, $length);\n" ++ " break;\n" ++ " default:\n" ++ " throw new RuntimeException(\"unknown field type[{$type}]\");\n" ++ " break;\n" + " }\n" + " }\n" + "\n" +diff --git a/ext-src/swoole_coroutine.cc b/ext-src/swoole_coroutine.cc +index 9dc0def33..2b9d1105b 100644 +--- a/ext-src/swoole_coroutine.cc ++++ b/ext-src/swoole_coroutine.cc +@@ -66,7 +66,12 @@ bool PHPCoroutine::interrupt_thread_running = false; + + extern void php_swoole_load_library(); + ++#if PHP_VERSION_ID < 80200 + static zend_bool *zend_vm_interrupt = nullptr; ++#else ++static zend_atomic_bool *zend_vm_interrupt = nullptr; ++#endif ++ + static user_opcode_handler_t ori_exit_handler = nullptr; + static user_opcode_handler_t ori_begin_silence_handler = nullptr; + static user_opcode_handler_t ori_end_silence_handler = nullptr; +@@ -406,12 +411,18 @@ void PHPCoroutine::interrupt_thread_start() { + if (interrupt_thread_running) { + return; + } ++#if PHP_VERSION_ID < 80200 + zend_vm_interrupt = &EG(vm_interrupt); ++#endif + interrupt_thread_running = true; + interrupt_thread = std::thread([]() { + swoole_signal_block_all(); + while (interrupt_thread_running) { ++#if PHP_VERSION_ID < 80200 + *zend_vm_interrupt = 1; ++#else ++ zend_atomic_bool_store_ex(&EG(vm_interrupt), true); ++#endif + std::this_thread::sleep_for(std::chrono::milliseconds(MAX_EXEC_MSEC / 2)); + } + }); +diff --git a/ext-src/swoole_http_response.cc b/ext-src/swoole_http_response.cc +index 50fe019bc..aa947f6fc 100644 +--- a/ext-src/swoole_http_response.cc ++++ b/ext-src/swoole_http_response.cc +@@ -395,7 +395,7 @@ static void http_build_header(HttpContext *ctx, String *response, size_t body_le + SW_HASHTABLE_FOREACH_END(); + } + +- if (!(header_flags & HTTP_HEADER_SERVER)) { ++ if (!(header_flags & HTTP_HEADER_SERVER) && SwooleG.enable_server_token) { + response->append(ZEND_STRL("Server: " SW_HTTP_SERVER_SOFTWARE "\r\n")); + } + +diff --git a/ext-src/swoole_websocket_server.cc b/ext-src/swoole_websocket_server.cc +index 578dc703e..8e2494f73 100644 +--- a/ext-src/swoole_websocket_server.cc ++++ b/ext-src/swoole_websocket_server.cc +@@ -274,9 +274,8 @@ void swoole_websocket_onRequest(HttpContext *ctx) { + "Connection: close\r\n" + "Content-Type: text/html; charset=UTF-8\r\n" + "Cache-Control: must-revalidate,no-cache,no-store\r\n" +- "Content-Length: 83\r\n" +- "Server: " SW_HTTP_SERVER_SOFTWARE "\r\n\r\n" +- "

HTTP 400 Bad Request


Powered by Swoole"; ++ "Content-Length: 55\r\n\r\n" ++ "

HTTP 400 Bad Request

"; + + ctx->send(ctx, (char *) bad_request, strlen(bad_request)); + ctx->end_ = 1; +diff --git a/include/swoole.h b/include/swoole.h +index 832f66b9e..ae07c0b4c 100644 +--- a/include/swoole.h ++++ b/include/swoole.h +@@ -646,6 +646,7 @@ struct Global { + struct utsname uname; + uint32_t max_sockets; + uint32_t max_concurrency; ++ bool enable_server_token; + //-----------------------[Memory]-------------------------- + MemoryPool *memory_pool; + Allocator std_allocator; +diff --git a/src/core/base.cc b/src/core/base.cc +index 4a241847b..11e170f2e 100644 +--- a/src/core/base.cc ++++ b/src/core/base.cc +@@ -172,6 +172,7 @@ void swoole_init(void) { + SwooleG.memory_pool = new swoole::GlobalMemory(SW_GLOBAL_MEMORY_PAGESIZE, true); + SwooleG.max_sockets = SW_MAX_SOCKETS_DEFAULT; + SwooleG.max_concurrency = 0; ++ SwooleG.enable_server_token = false; + struct rlimit rlmt; + if (getrlimit(RLIMIT_NOFILE, &rlmt) < 0) { + swoole_sys_warning("getrlimit() failed"); +diff --git a/thirdparty/php/curl/curl_private.h b/thirdparty/php/curl/curl_private.h +index e64bbbb6e..4b8e2128a 100644 +--- a/thirdparty/php/curl/curl_private.h ++++ b/thirdparty/php/curl/curl_private.h +@@ -68,12 +68,22 @@ typedef struct { + int method; + } php_curl_progress, php_curl_fnmatch, php_curlm_server_push; + ++typedef struct { ++ zval func_name; ++ zend_fcall_info_cache fci_cache; ++} php_curl_callback; ++ + typedef struct { + php_curl_write *write; + php_curl_write *write_header; + php_curl_read *read; + zval std_err; + php_curl_progress *progress; ++#if PHP_VERSION_ID >= 80200 ++#if LIBCURL_VERSION_NUM >= 0x072000 ++ php_curl_callback *xferinfo; ++#endif ++#endif + #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ + php_curl_fnmatch *fnmatch; + #endif +@@ -214,8 +224,13 @@ static inline php_curlsh *curl_share_from_obj(zend_object *obj) { + + #define Z_CURL_SHARE_P(zv) curl_share_from_obj(Z_OBJ_P(zv)) + void curl_multi_register_class(const zend_function_entry *method_entries); ++ ++#if PHP_VERSION_ID < 80200 + int swoole_curl_cast_object(zend_object *obj, zval *result, int type); + #else ++zend_result swoole_curl_cast_object(zend_object *obj, zval *result, int type); ++#endif ++#else + #define Z_CURL_P(zv) swoole_curl_get_handle(zv) + #endif /* PHP8 end */ + +diff --git a/thirdparty/php/curl/interface.cc b/thirdparty/php/curl/interface.cc +index 43a289d00..3897b58fd 100644 +--- a/thirdparty/php/curl/interface.cc ++++ b/thirdparty/php/curl/interface.cc +@@ -85,6 +85,9 @@ static zend_object_handlers swoole_native_curl_exception_handlers; + #if PHP_VERSION_ID < 80000 + static int le_curl; + static int le_curl_multi_handle; ++static int le_curl_share_handle; ++#define le_curl_share_handle_name "cURL Share Handle" ++ + + int swoole_curl_get_le_curl() { + return le_curl; +@@ -454,6 +457,14 @@ static HashTable *swoole_curl_get_gc(zend_object *object, zval **table, int *n) + zend_get_gc_buffer_add_zval(gc_buffer, &curl_handlers(curl)->progress->func_name); + } + ++#if PHP_VERSION_ID >= 80200 ++#if LIBCURL_VERSION_NUM >= 0x072000 ++ if (curl->handlers.xferinfo) { ++ zend_get_gc_buffer_add_zval(gc_buffer, &curl_handlers(curl)->xferinfo->func_name); ++ } ++#endif ++#endif ++ + #if LIBCURL_VERSION_NUM >= 0x071500 + if (curl_handlers(curl)->fnmatch) { + zend_get_gc_buffer_add_zval(gc_buffer, &curl_handlers(curl)->fnmatch->func_name); +@@ -472,6 +483,7 @@ static HashTable *swoole_curl_get_gc(zend_object *object, zval **table, int *n) + return zend_std_get_properties(object); + } + ++#if PHP_VERSION_ID < 80200 + int swoole_curl_cast_object(zend_object *obj, zval *result, int type) { + if (type == IS_LONG) { + /* For better backward compatibility, make (int) $curl_handle return the object ID, +@@ -482,6 +494,19 @@ int swoole_curl_cast_object(zend_object *obj, zval *result, int type) { + + return zend_std_cast_object_tostring(obj, result, type); + } ++#else ++zend_result swoole_curl_cast_object(zend_object *obj, zval *result, int type) { ++ if (type == IS_LONG) { ++ /* For better backward compatibility, make (int) $curl_handle return the object ID, ++ * similar to how it previously returned the resource ID. */ ++ ZVAL_LONG(result, obj->handle); ++ return SUCCESS; ++ } ++ ++ return zend_std_cast_object_tostring(obj, result, type); ++} ++#endif ++ + #endif + + void swoole_native_curl_mshutdown() {} +@@ -928,6 +953,11 @@ php_curl *swoole_curl_alloc_handle() + curl_handlers(ch)->write_header = (php_curl_write *) ecalloc(1, sizeof(php_curl_write)); + curl_handlers(ch)->read = (php_curl_read *) ecalloc(1, sizeof(php_curl_read)); + curl_handlers(ch)->progress = NULL; ++#if PHP_VERSION_ID >= 80200 ++#if LIBCURL_VERSION_NUM >= 0x072000 ++ curl_handlers(ch)->xferinfo = NULL; ++#endif ++#endif + #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ + curl_handlers(ch)->fnmatch = NULL; + #endif +@@ -2147,6 +2177,7 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ + /* Curl off_t options */ + case CURLOPT_MAX_RECV_SPEED_LARGE: + case CURLOPT_MAX_SEND_SPEED_LARGE: ++ case CURLOPT_MAXFILESIZE_LARGE: + #if LIBCURL_VERSION_NUM >= 0x073b00 /* Available since 7.59.0 */ + case CURLOPT_TIMEVALUE_LARGE: + #endif +@@ -2206,9 +2237,25 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ + } + break; + +- case CURLOPT_SHARE: { +- php_error_docref(NULL, E_WARNING, "CURLOPT_SHARE option is not supported"); +- } break; ++ case CURLOPT_SHARE: ++#if PHP_VERSION_ID >= 80000 ++ if (Z_TYPE_P(zvalue) == IS_OBJECT && Z_OBJCE_P(zvalue) == curl_share_ce) { ++ php_curlsh *sh = Z_CURL_SHARE_P(zvalue); ++ curl_easy_setopt(ch->cp, CURLOPT_SHARE, sh->share); ++ ++ if (ch->share) { ++ OBJ_RELEASE(&ch->share->std); ++ } ++ GC_ADDREF(&sh->std); ++ ch->share = sh; ++ } ++#else ++ php_curlsh *sh; ++ if ((sh = (php_curlsh *) zend_fetch_resource_ex(zvalue, le_curl_share_handle_name, le_curl_share_handle))) { ++ curl_easy_setopt(ch->cp, CURLOPT_SHARE, sh->share); ++ } ++#endif ++ break; + + #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ + case CURLOPT_FNMATCH_FUNCTION: +@@ -2852,6 +2899,15 @@ static void _php_curl_free(php_curl *ch) { + efree(curl_handlers(ch)->progress); + } + ++#if PHP_VERSION_ID >= 80200 ++#if LIBCURL_VERSION_NUM >= 0x072000 ++ if (curl_handlers(ch)->xferinfo) { ++ zval_ptr_dtor(&curl_handlers(ch)->xferinfo->func_name); ++ efree(curl_handlers(ch)->xferinfo); ++ } ++#endif ++#endif ++ + #if LIBCURL_VERSION_NUM >= 0x071500 + if (curl_handlers(ch)->fnmatch) { + zval_ptr_dtor(&curl_handlers(ch)->fnmatch->func_name); +@@ -2957,6 +3013,15 @@ static void _php_curl_reset_handlers(php_curl *ch) { + curl_handlers(ch)->progress = NULL; + } + ++#if PHP_VERSION_ID >= 80200 ++#if LIBCURL_VERSION_NUM >= 0x072000 ++ if (curl_handlers(ch)->xferinfo) { ++ zval_ptr_dtor(&curl_handlers(ch)->xferinfo->func_name); ++ efree(curl_handlers(ch)->xferinfo); ++ } ++#endif ++#endif ++ + #if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */ + if (curl_handlers(ch)->fnmatch) { + zval_ptr_dtor(&curl_handlers(ch)->fnmatch->func_name); diff --git a/php-pecl-openswoole.spec b/php-pecl-openswoole.spec index d5c424c..41e2804 100644 --- a/php-pecl-openswoole.spec +++ b/php-pecl-openswoole.spec @@ -35,13 +35,18 @@ Summary: PHP's asynchronous concurrent distributed networking framework Name: %{?scl_prefix}php-pecl-%{pecl_name} Version: %{upstream_version}%{?upstream_prever:~%{upstream_prever}} -Release: 1%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} +Release: 2%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} # Extension is ASL 2.0 # Hiredis is BSD License: ASL 2.0 and BSD URL: https://pecl.php.net/package/%{pecl_name} Source0: https://pecl.php.net/get/%{pecl_name}-%{upstream_version}%{?upstream_prever}.tgz +# git checkout 4.x +# git diff v4.11.1 -- ext-src/ include/ thirdparty/ src/ +# remove include/swoole_version.h +Patch0: %{pecl_name}-php82.patch + BuildRequires: make BuildRequires: %{?dtsprefix}gcc BuildRequires: %{?dtsprefix}gcc-c++ @@ -86,16 +91,7 @@ Provides: %{?scl_prefix}php-pecl(%{pecl_name})%{?_isa} = %{version} Conflicts: %{?scl_prefix}php-pecl-swoole Conflicts: %{?scl_prefix}php-pecl-swoole2 Conflicts: %{?scl_prefix}php-pecl-swoole4 - -%if "%{?packager}" == "Remi Collet" && 0%{!?scl:1} && 0%{?rhel} -Obsoletes: php74-pecl-%{pecl_name} <= %{version} -%if "%{php_version}" > "8.0" -Obsoletes: php80-pecl-%{pecl_name} <= %{version} -%endif -%if "%{php_version}" > "8.1" -Obsoletes: php81-pecl-%{pecl_name} <= %{version} -%endif -%endif +Conflicts: %{?scl_prefix}php-pecl-swoole5 %description @@ -148,6 +144,10 @@ sed \ cd NTS +%if "%{php_version}" > "8.2" +%patch0 -p1 -b .up +%endif + cp -p thirdparty/hiredis/COPYING hiredis-COPYING cp -p thirdparty/nghttp2/COPYING nghttp2-COPYING @@ -322,6 +322,9 @@ cd ../ZTS %changelog +* Fri Sep 16 2022 Remi Collet - 4.11.1-2 +- add upstream patches for PHP 8.2 + * Fri Apr 29 2022 Remi Collet - 4.11.1-1 - update to 4.11.1 -- cgit