From bc5142ab94cf25099df9261cfb21af76af750129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A9=E5=A4=A9=E5=B3=B0-Rango?= Date: Wed, 17 Nov 2021 12:48:13 +0800 Subject: [PATCH] Update version (#4495) * Update version * Update package.xml --- CMakeLists.txt | 2 +- ext-src/php_swoole_library.h | 702 +++++++++++++++++++++++++++++++++-- include/swoole_version.h | 4 +- package.xml | 56 +-- tools/build-library.php | 8 + 5 files changed, 718 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c84ff2b4317..abe50062500 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ PROJECT(libswoole) ENABLE_LANGUAGE(ASM) -set(SWOOLE_VERSION 4.8.2-dev) +set(SWOOLE_VERSION 4.8.2) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -g") diff --git a/ext-src/php_swoole_library.h b/ext-src/php_swoole_library.h index c9ca4103b23..f9cef8df115 100644 --- a/ext-src/php_swoole_library.h +++ b/ext-src/php_swoole_library.h @@ -1,6 +1,6 @@ /** * ----------------------------------------------------------------------- - * Generated by tools/build-library.php, Please DO NOT modify! + * Generated by tools/build-library.php, Please DO NOT modify! +----------------------------------------------------------------------+ | Swoole | +----------------------------------------------------------------------+ @@ -11,10 +11,10 @@ | If you did not receive a copy of the Apache2.0 license and are unable| | to obtain it through the world-wide-web, please send a note to | | license@swoole.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ + +----------------------------------------------------------------------+ */ -/* $Id: 3f20e97a3f11d81aeef259a6f476a9af653f5d5c */ +/* $Id: 4350b6c5099ebd96937d7349053a7ad0f60f9ecf */ static const char* swoole_library_source_constants = "\n" @@ -167,8 +167,6 @@ static const char* swoole_library_source_core_constant = "\n" " public const OPTION_SOCKET_TIMEOUT = 'socket_timeout';\n" "\n" - " public const OPTION_MAX_CONCURRENCY = 'max_concurrency';\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" @@ -301,6 +299,8 @@ static const char* swoole_library_source_core_constant = "\n" " public const OPTION_DNS_CACHE_CAPACITY = 'dns_cache_capacity';\n" "\n" + " public const OPTION_MAX_CONCURRENCY = 'max_concurrency';\n" + "\n" " public const OPTION_RECONNECT = 'reconnect';\n" "\n" " public const OPTION_DEFER = 'defer';\n" @@ -512,6 +512,8 @@ static const char* swoole_library_source_core_constant = " public const OPTION_ADMIN_SERVER = 'admin_server';\n" "\n" " \n" + "\n" + " public const OPTION_HTTP_CLIENT_DRIVER = 'http_client_driver';\n" "}\n"; static const char* swoole_library_source_core_string_object = @@ -1681,6 +1683,53 @@ static const char* swoole_library_source_core_coroutine_barrier = " }\n" "}\n"; +static const char* swoole_library_source_core_coroutine_http_client_proxy = + "\n" + "\n" + "\n" + "declare(strict_types=1);\n" + "\n" + "namespace Swoole\\Coroutine\\Http;\n" + "\n" + "class ClientProxy\n" + "{\n" + " private $body;\n" + "\n" + " private $statusCode;\n" + "\n" + " private $headers;\n" + "\n" + " private $cookies;\n" + "\n" + " public function __construct($body, $statusCode, $headers, $cookies)\n" + " {\n" + " $this->body = $body;\n" + " $this->statusCode = $statusCode;\n" + " $this->headers = $headers;\n" + " $this->cookies = $cookies;\n" + " }\n" + "\n" + " public function getBody()\n" + " {\n" + " return $this->body;\n" + " }\n" + "\n" + " public function getStatusCode()\n" + " {\n" + " return $this->statusCode;\n" + " }\n" + "\n" + " public function getHeaders()\n" + " {\n" + " return $this->headers;\n" + " }\n" + "\n" + " public function getCookies()\n" + " {\n" + " return $this->cookies;\n" + " }\n" + "}\n"; + static const char* swoole_library_source_core_coroutine_http_functions = "\n" "\n" @@ -1692,8 +1741,35 @@ static const char* swoole_library_source_core_coroutine_http_functions = "use Swoole\\Coroutine\\Http\\Client\\Exception;\n" "\n" "\n" - "function request(string $url, string $method, $data = null, array $options = null, array $headers = null, array $cookies = null)\n" - "{\n" + "function request(\n" + " string $url,\n" + " string $method,\n" + " $data = null,\n" + " array $options = null,\n" + " array $headers = null,\n" + " array $cookies = null\n" + "): ClientProxy {\n" + " $driver = swoole_library_get_option('http_client_driver');\n" + " switch ($driver) {\n" + " case 'curl':\n" + " return request_with_curl($url, $method, $data, $options, $headers, $cookies);\n" + " case 'stream':\n" + " return request_with_stream($url, $method, $data, $options, $headers, $cookies);\n" + " case 'swoole':\n" + " default:\n" + " return request_with_http_client($url, $method, $data, $options, $headers, $cookies);\n" + " }\n" + "}\n" + "\n" + "\n" + "function request_with_http_client(\n" + " string $url,\n" + " string $method,\n" + " $data = null,\n" + " array $options = null,\n" + " array $headers = null,\n" + " array $cookies = null\n" + "): ClientProxy {\n" " $info = parse_url($url);\n" " if (empty($info['scheme'])) {\n" " throw new Exception('The URL given is illegal [no scheme]');\n" @@ -1723,19 +1799,138 @@ static const char* swoole_library_source_core_coroutine_http_functions = " $request_url .= '?' . $info['query'];\n" " }\n" " if ($client->execute($request_url)) {\n" - " return $client;\n" + " return new ClientProxy(\n" + " $client->getBody(),\n" + " $client->getStatusCode(),\n" + " $client->getHeaders(),\n" + " $client->getCookies()\n" + " );\n" " }\n" - " return false;\n" + " throw new Exception($client->errMsg, $client->errCode);\n" + "}\n" + "\n" + "\n" + "function request_with_curl(\n" + " string $url,\n" + " string $method,\n" + " $data = null,\n" + " array $options = null,\n" + " array $headers = null,\n" + " array $cookies = null\n" + "): ClientProxy {\n" + " $ch = curl_init($url);\n" + " if (empty($ch)) {\n" + " throw new Exception('failed to curl_init');\n" + " }\n" + " curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n" + " curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method));\n" + " $responseHeaders = $responseCookies = [];\n" + " curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $header) use (&$responseHeaders, &$responseCookies) {\n" + " $len = strlen($header);\n" + " $header = explode(':', $header, 2);\n" + " if (count($header) < 2) {\n" + " return $len;\n" + " }\n" + " $headerKey = strtolower(trim($header[0]));\n" + " if ($headerKey == 'set-cookie') {\n" + " [$k, $v] = explode('=', $header[1]);\n" + " $responseCookies[$k] = $v;\n" + " } else {\n" + " $responseHeaders[$headerKey][] = trim($header[1]);\n" + " }\n" + " return $len;\n" + " });\n" + " if ($data) {\n" + " curl_setopt($ch, CURLOPT_POSTFIELDS, $data);\n" + " }\n" + " if ($headers) {\n" + " curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);\n" + " }\n" + " if ($cookies) {\n" + " $cookie_str = '';\n" + " foreach ($cookies as $k => $v) {\n" + " $cookie_str .= \"{$k}={$v}; \";\n" + " }\n" + " curl_setopt($ch, CURLOPT_COOKIE, $cookie_str);\n" + " }\n" + " if (isset($options['timeout'])) {\n" + " if (is_float($options['timeout'])) {\n" + " curl_setopt($ch, CURLOPT_TIMEOUT_MS, intval($options['timeout'] * 1000));\n" + " curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, intval($options['timeout'] * 1000));\n" + " } else {\n" + " curl_setopt($ch, CURLOPT_TIMEOUT, intval($options['timeout']));\n" + " curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, intval($options['timeout']));\n" + " }\n" + " }\n" + " if (isset($options['connect_timeout'])) {\n" + " if (is_float($options['connect_timeout'])) {\n" + " curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, intval($options['connect_timeout'] * 1000));\n" + " } else {\n" + " curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, intval($options['connect_timeout']));\n" + " }\n" + " }\n" + " $body = curl_exec($ch);\n" + " if ($body !== false) {\n" + " return new ClientProxy($body, curl_getinfo($ch, CURLINFO_HTTP_CODE), $responseHeaders, $responseCookies);\n" + " }\n" + " throw new Exception(curl_error($ch), curl_errno($ch));\n" "}\n" "\n" "\n" - "function post(string $url, $data, array $options = null, array $headers = null, array $cookies = null)\n" + "function request_with_stream(\n" + " string $url,\n" + " string $method,\n" + " $data = null,\n" + " array $options = null,\n" + " array $headers = null,\n" + " array $cookies = null\n" + "): ClientProxy {\n" + " $stream_options = [\n" + " 'http' => [\n" + " 'method' => $method,\n" + " ],\n" + " ];\n" + " $headerStr = '';\n" + " if ($headers) {\n" + " foreach ($headers as $k => $v) {\n" + " $headerStr .= \"{$k}: {$v}\\r\\n\";\n" + " }\n" + " }\n" + " if ($cookies) {\n" + " foreach ($cookies as $k => $v) {\n" + " $headerStr .= \"Cookie: {$k}={$v}\\r\\n\";\n" + " }\n" + " }\n" + " if (isset($options['timeout'])) {\n" + " $stream_options['http']['timeout'] = intval($options['timeout']);\n" + " }\n" + " if ($data) {\n" + " if (is_array($data)) {\n" + " $headerStr .= \"Content-type: application/x-www-form-urlencoded\\r\\n\";\n" + " $stream_options['http']['content'] = http_build_query($data);\n" + " } else {\n" + " $stream_options['http']['content'] = strval($data);\n" + " }\n" + " }\n" + " if ($headerStr) {\n" + " $stream_options['http']['header'] = $headerStr;\n" + " }\n" + " $body = file_get_contents($url, false, stream_context_create($stream_options));\n" + " if ($body) {\n" + " return new ClientProxy($body, 200, [], []);\n" + " }\n" + " $error = error_get_last();\n" + " throw new Exception($error['message']);\n" + "}\n" + "\n" + "\n" + "function post(string $url, $data, array $options = null, array $headers = null, array $cookies = null): ClientProxy\n" "{\n" " return request($url, 'POST', $data, $options, $headers, $cookies);\n" "}\n" "\n" "\n" - "function get(string $url, array $options = null, array $headers = null, array $cookies = null)\n" + "function get(string $url, array $options = null, array $headers = null, array $cookies = null): ClientProxy\n" "{\n" " return request($url, 'GET', null, $options, $headers, $cookies);\n" "}\n"; @@ -6930,10 +7125,15 @@ static const char* swoole_library_source_core_server_admin = " {\n" " $total = 0;\n" "\n" - " $result['master'] = self::getProcessMemoryRealUsage($server->master_pid);\n" + " $result['master'] = $result['manager'] = 0;\n" + " if (self::haveMasterProcess($server)) {\n" + " $result['master'] = self::getProcessMemoryRealUsage($server->master_pid);\n" + " }\n" " $total += $result['master'];\n" "\n" - " $result['manager'] = self::getProcessMemoryRealUsage($server->manager_pid);\n" + " if (self::haveManagerProcess($server)) {\n" + " $result['manager'] = self::getProcessMemoryRealUsage($server->manager_pid);\n" + " }\n" " $total += $result['manager'];\n" "\n" " $n = $server->setting['worker_num'] + $server->setting['task_worker_num'];\n" @@ -6959,10 +7159,17 @@ static const char* swoole_library_source_core_server_admin = " {\n" " $total = 0;\n" "\n" - " $result['master'] = self::getProcessCpuUsage($server->master_pid);\n" + " $result['master'] = $result['manager'] = 0;\n" + " if (self::haveMasterProcess($server)) {\n" + " $result['master'] = self::getProcessCpuUsage($server->master_pid);\n" + " }\n" + "\n" " $total += $result['master'][1] ?? 0;\n" "\n" - " $result['manager'] = self::getProcessCpuUsage($server->manager_pid);\n" + " if (self::haveManagerProcess($server)) {\n" + " $result['manager'] = self::getProcessCpuUsage($server->manager_pid);\n" + " }\n" + "\n" " $total += $result['manager'][1] ?? 0;\n" "\n" " $n = $server->setting['worker_num'] + $server->setting['task_worker_num'];\n" @@ -7118,12 +7325,7 @@ static const char* swoole_library_source_core_server_admin = " }\n" " $process_type = SWOOLE_SERVER_COMMAND_REACTOR_THREAD;\n" " if (empty($server->setting['reactor_num'])) {\n" - " if (empty($server->setting['worker_num'])) {\n" - " $cpu_num = swoole_cpu_num();\n" - " $reactor_num = $cpu_num >= 8 ? 8 : $cpu_num;\n" - " } else {\n" - " $reactor_num = $server->setting['worker_num'];\n" - " }\n" + " $reactor_num = $server->setting['worker_num'];\n" " } else {\n" " $reactor_num = $server->setting['reactor_num'];\n" " }\n" @@ -7136,7 +7338,7 @@ static const char* swoole_library_source_core_server_admin = " private static function handlerGetAllWorker($cmd, $data, Server $server, bool $json_decode = false)\n" " {\n" " $process_type = SWOOLE_SERVER_COMMAND_EVENT_WORKER;\n" - " $worker_num = empty($server->setting['worker_num']) ? swoole_cpu_num() : $server->setting['worker_num'];\n" + " $worker_num = $server->setting['worker_num'];\n" " $list = [];\n" " for ($process_id = 0; $process_id < $worker_num; $process_id++) {\n" " $list[\"worker-{$process_id}\"] = $server->command($cmd, $process_id, $process_type, $data, $json_decode);\n" @@ -7161,7 +7363,7 @@ static const char* swoole_library_source_core_server_admin = " private static function getProcessCpuUsage($pid)\n" " {\n" " \n" - " if (PHP_OS_FAMILY !== 'Linux') {\n" + " if (PHP_OS_FAMILY !== 'Linux' || !file_exists(\"/proc/{$pid}/stat\")) {\n" " return [0];\n" " }\n" "\n" @@ -7194,10 +7396,10 @@ static const char* swoole_library_source_core_server_admin = " {\n" " $array = [];\n" " \n" - " if (PHP_OS_FAMILY !== 'Linux') {\n" + " if (PHP_OS_FAMILY !== 'Linux' || !file_exists(\"/proc/{$pid}/status\")) {\n" " return $array;\n" " }\n" - " $status = swoole_string(trim(file_get_contents('/proc/' . $pid . '/status')));\n" + " $status = swoole_string(trim(file_get_contents(\"/proc/{$pid}/status\")));\n" " $lines = $status->split(\"\\n\");\n" " foreach ($lines as $l) {\n" " if (empty($l)) {\n" @@ -7252,6 +7454,24 @@ static const char* swoole_library_source_core_server_admin = " return $size;\n" " }\n" "\n" + " private static function haveMasterProcess(Server $server): bool\n" + " {\n" + " if ($server->mode === SWOOLE_BASE) {\n" + " return false;\n" + " }\n" + "\n" + " return true;\n" + " }\n" + "\n" + " private static function haveManagerProcess(Server $server): bool\n" + " {\n" + " if ($server->mode === SWOOLE_BASE && $server->getManagerPid() === 0) {\n" + " return false;\n" + " }\n" + "\n" + " return true;\n" + " }\n" + "\n" " private static function json($data, $code = 0)\n" " {\n" " $result = json_encode(['code' => $code, 'data' => $data], JSON_INVALID_UTF8_IGNORE);\n" @@ -7299,7 +7519,6 @@ static const char* swoole_library_source_core_server_helper = " 'socket_recv_timeout' => true,\n" " 'socket_buffer_size' => true,\n" " 'socket_timeout' => true,\n" - " 'max_concurrency' => true,\n" " ];\n" "\n" " public const SERVER_OPTIONS = [\n" @@ -7313,6 +7532,8 @@ static const char* swoole_library_source_core_server_helper = " 'worker_num' => true,\n" " 'max_wait_time' => true,\n" " 'max_queued_bytes' => true,\n" + " 'max_concurrency' => true,\n" + " 'worker_max_concurrency' => true,\n" " 'enable_coroutine' => true,\n" " 'send_timeout' => true,\n" " 'dispatch_mode' => true,\n" @@ -7438,8 +7659,10 @@ static const char* swoole_library_source_core_server_helper = " 'enable_preemptive_scheduler' => true,\n" " 'c_stack_size' => true,\n" " 'stack_size' => true,\n" + " 'name_resolver' => true,\n" " 'dns_cache_expire' => true,\n" " 'dns_cache_capacity' => true,\n" + " 'max_concurrency' => true,\n" " ];\n" "\n" " public const HELPER_OPTIONS = [\n" @@ -7547,6 +7770,401 @@ static const char* swoole_library_source_core_server_helper = " }\n" "}\n"; +static const char* swoole_library_source_core_name_resolver = + "\n" + "\n" + "\n" + "declare(strict_types=1);\n" + "\n" + "namespace Swoole;\n" + "\n" + "use RuntimeException;\n" + "use Swoole\\Coroutine\\Http\\ClientProxy;\n" + "use Swoole\\NameResolver\\Cluster;\n" + "use Swoole\\NameResolver\\Exception;\n" + "\n" + "abstract class NameResolver\n" + "{\n" + " protected $baseUrl;\n" + "\n" + " protected $prefix;\n" + "\n" + " protected $info;\n" + "\n" + " private $filter_fn;\n" + "\n" + " public function __construct($url, $prefix = 'swoole_service_')\n" + " {\n" + " $this->checkServerUrl($url);\n" + " $this->prefix = $prefix;\n" + " }\n" + "\n" + " abstract public function join(string $name, string $ip, int $port, array $options = []): bool;\n" + "\n" + " abstract public function leave(string $name, string $ip, int $port): bool;\n" + "\n" + " abstract public function getCluster(string $name): ?Cluster;\n" + "\n" + " public function withFilter(callable $fn): self\n" + " {\n" + " $this->filter_fn = $fn;\n" + " return $this;\n" + " }\n" + "\n" + " public function getFilter()\n" + " {\n" + " return $this->filter_fn;\n" + " }\n" + "\n" + " public function hasFilter(): bool\n" + " {\n" + " return !empty($this->filter_fn);\n" + " }\n" + "\n" + " \n" + " public function lookup(string $name)\n" + " {\n" + " if ($this->hasFilter() and ($this->getFilter())($name) !== true) {\n" + " return null;\n" + " }\n" + " $cluster = $this->getCluster($name);\n" + " \n" + " if ($cluster == null) {\n" + " return '';\n" + " }\n" + " \n" + " if ($cluster->count() == 1) {\n" + " return $cluster->pop();\n" + " }\n" + " return $cluster;\n" + " }\n" + "\n" + " \n" + " protected function checkServerUrl($url)\n" + " {\n" + " $info = parse_url($url);\n" + " if (empty($info['scheme']) or empty($info['host'])) {\n" + " throw new RuntimeException(\"invalid url parameter '{$url}'\");\n" + " }\n" + " if (!filter_var($info['host'], FILTER_VALIDATE_IP)) {\n" + " $info['ip'] = gethostbyname($info['host']);\n" + " if (!filter_var($info['ip'], FILTER_VALIDATE_IP)) {\n" + " throw new RuntimeException(\"Failed to resolve host '{$info['host']}'\");\n" + " }\n" + " } else {\n" + " $info['ip'] = $info['host'];\n" + " }\n" + " $baseUrl = $info['scheme'] . '://' . $info['ip'];\n" + " if (!empty($info['port'])) {\n" + " $baseUrl .= \":{$info['port']}\";\n" + " }\n" + " if (!empty($info['path'])) {\n" + " $baseUrl .= rtrim($info['path'], '/');\n" + " }\n" + " $this->baseUrl = $baseUrl;\n" + " $this->info = $info;\n" + " }\n" + "\n" + " \n" + " protected function checkResponse($r, $url)\n" + " {\n" + " if (empty($r)) {\n" + " throw new Exception(\"failed to request URL({$url})\");\n" + " }\n" + " if ($r->getStatusCode() !== 200) {\n" + " $msg = '';\n" + " if (!empty($r->errMsg)) {\n" + " $msg .= 'errMsg: ' . $r->errMsg;\n" + " }\n" + " $body = $r->getBody();\n" + " if (empty($r->errMsg)) {\n" + " $msg .= 'Http Body: ' . $body;\n" + " }\n" + " throw new Exception($msg, $r->errCode ?: $r->getStatusCode());\n" + " }\n" + " return true;\n" + " }\n" + "}\n"; + +static const char* swoole_library_source_core_name_resolver_exception = + "\n" + "\n" + "\n" + "declare(strict_types=1);\n" + "\n" + "\n" + "\n" + "namespace Swoole\\NameResolver;\n" + "\n" + "class Exception extends \\RuntimeException\n" + "{\n" + "}\n"; + +static const char* swoole_library_source_core_name_resolver_cluster = + "\n" + "\n" + "\n" + "declare(strict_types=1);\n" + "\n" + "namespace Swoole\\NameResolver;\n" + "\n" + "use Swoole\\Exception;\n" + "\n" + "class Cluster\n" + "{\n" + " \n" + " private $nodes = [];\n" + "\n" + " \n" + " public function add(string $host, int $port, int $weight = 100): void\n" + " {\n" + " if (!filter_var($host, FILTER_VALIDATE_IP)) {\n" + " throw new Exception(\"Bad IP Address [{$host}]\");\n" + " }\n" + " if ($port < 0 or $port > 65535) {\n" + " throw new Exception(\"Bad Port [{$port}]\");\n" + " }\n" + " if ($weight < 0 or $weight > 100) {\n" + " throw new Exception(\"Bad Weight [{$weight}]\");\n" + " }\n" + " $this->nodes[] = ['host' => $host, 'port' => $port, 'weight' => $weight];\n" + " }\n" + "\n" + " \n" + " public function pop()\n" + " {\n" + " if (empty($this->nodes)) {\n" + " return false;\n" + " }\n" + " $index = array_rand($this->nodes, 1);\n" + " $node = $this->nodes[$index];\n" + " unset($this->nodes[$index]);\n" + " return $node;\n" + " }\n" + "\n" + " public function count(): int\n" + " {\n" + " return count($this->nodes);\n" + " }\n" + "}\n"; + +static const char* swoole_library_source_core_name_resolver_redis = + "\n" + "\n" + "\n" + "declare(strict_types=1);\n" + "\n" + "\n" + "namespace Swoole\\NameResolver;\n" + "\n" + "use Swoole\\NameResolver;\n" + "\n" + "class Redis extends NameResolver\n" + "{\n" + " private $serverHost;\n" + "\n" + " private $serverPort;\n" + "\n" + " public function __construct($url, $prefix = 'swoole:service:')\n" + " {\n" + " parent::__construct($url, $prefix);\n" + " $this->serverHost = $this->info['ip'];\n" + " $this->serverPort = $this->info['port'] ?? 6379;\n" + " }\n" + "\n" + " public function join(string $name, string $ip, int $port, array $options = []): bool\n" + " {\n" + " if (($redis = $this->connect()) === false) {\n" + " return false;\n" + " }\n" + " if ($redis->sAdd($this->prefix . $name, $ip . ':' . $port) === false) {\n" + " return false;\n" + " }\n" + " return true;\n" + " }\n" + "\n" + " public function leave(string $name, string $ip, int $port): bool\n" + " {\n" + " if (($redis = $this->connect()) === false) {\n" + " return false;\n" + " }\n" + " if ($redis->sRem($this->prefix . $name, $ip . ':' . $port) === false) {\n" + " return false;\n" + " }\n" + " return true;\n" + " }\n" + "\n" + " public function getCluster(string $name): ?Cluster\n" + " {\n" + " if (($redis = $this->connect()) === false) {\n" + " return null;\n" + " }\n" + " $members = $redis->sMembers($this->prefix . $name);\n" + " if (empty($members)) {\n" + " return null;\n" + " }\n" + " $cluster = new Cluster();\n" + " foreach ($members as $m) {\n" + " [$host, $port] = explode(':', $m);\n" + " $cluster->add($host, intval($port));\n" + " }\n" + " return $cluster;\n" + " }\n" + "\n" + " protected function connect()\n" + " {\n" + " $redis = new \\redis();\n" + " if ($redis->connect($this->serverHost, $this->serverPort) === false) {\n" + " return false;\n" + " }\n" + " return $redis;\n" + " }\n" + "}\n"; + +static const char* swoole_library_source_core_name_resolver_nacos = + "\n" + "\n" + "\n" + "declare(strict_types=1);\n" + "\n" + "\n" + "namespace Swoole\\NameResolver;\n" + "\n" + "use Swoole\\Coroutine;\n" + "use Swoole\\NameResolver;\n" + "\n" + "class Nacos extends NameResolver\n" + "{\n" + " \n" + " public function join(string $name, string $ip, int $port, array $options = []): bool\n" + " {\n" + " $params['port'] = $port;\n" + " $params['ip'] = $ip;\n" + " $params['healthy'] = 'true';\n" + " $params['weight'] = $options['weight'] ?? 100;\n" + " $params['encoding'] = $options['encoding'] ?? 'utf-8';\n" + " $params['namespaceId'] = $options['namespaceId'] ?? 'public';\n" + " $params['serviceName'] = $this->prefix . $name;\n" + "\n" + " $url = $this->baseUrl . '/nacos/v1/ns/instance?' . http_build_query($params);\n" + " $r = Coroutine\\Http\\post($url, []);\n" + " return $this->checkResponse($r, $url);\n" + " }\n" + "\n" + " \n" + " public function leave(string $name, string $ip, int $port): bool\n" + " {\n" + " $params['port'] = $port;\n" + " $params['ip'] = $ip;\n" + " $params['serviceName'] = $this->prefix . $name;\n" + "\n" + " $url = $this->baseUrl . '/nacos/v1/ns/instance?' . http_build_query($params);\n" + " $r = Coroutine\\Http\\request($this->baseUrl . '/nacos/v1/ns/instance?' . http_build_query($params), 'DELETE');\n" + " return $this->checkResponse($r, $url);\n" + " }\n" + "\n" + " \n" + " public function getCluster(string $name): ?Cluster\n" + " {\n" + " $params['serviceName'] = $this->prefix . $name;\n" + "\n" + " $url = $this->baseUrl . '/nacos/v1/ns/instance/list?' . http_build_query($params);\n" + " $r = Coroutine\\Http\\get($url);\n" + " if (!$this->checkResponse($r, $url)) {\n" + " return null;\n" + " }\n" + " $result = json_decode($r->getBody());\n" + " if (empty($result)) {\n" + " return null;\n" + " }\n" + " $cluster = new Cluster();\n" + " foreach ($result->hosts as $node) {\n" + " $cluster->add($node->ip, $node->port, $node->weight);\n" + " }\n" + " return $cluster;\n" + " }\n" + "}\n"; + +static const char* swoole_library_source_core_name_resolver_consul = + "\n" + "\n" + "\n" + "declare(strict_types=1);\n" + "\n" + "\n" + "namespace Swoole\\NameResolver;\n" + "\n" + "use Swoole\\NameResolver;\n" + "use function Swoole\\Coroutine\\Http\\get;\n" + "use function Swoole\\Coroutine\\Http\\request;\n" + "\n" + "class Consul extends NameResolver\n" + "{\n" + " public function join(string $name, string $ip, int $port, array $options = []): bool\n" + " {\n" + " $weight = $options['weight'] ?? 100;\n" + " $data = [\n" + " 'ID' => $this->getServiceId($name, $ip, $port),\n" + " 'Name' => $this->prefix . $name,\n" + " 'Address' => $ip,\n" + " 'Port' => $port,\n" + " 'EnableTagOverride' => false,\n" + " 'Weights' => [\n" + " 'Passing' => $weight,\n" + " 'Warning' => 1,\n" + " ],\n" + " ];\n" + " $url = $this->baseUrl . '/v1/agent/service/register';\n" + " $r = request($url, 'PUT', json_encode($data));\n" + " return $this->checkResponse($r, $url);\n" + " }\n" + "\n" + " public function leave(string $name, string $ip, int $port): bool\n" + " {\n" + " $url = $this->baseUrl . '/v1/agent/service/deregister/' . $this->getServiceId(\n" + " $name,\n" + " $ip,\n" + " $port\n" + " );\n" + " $r = request($url, 'PUT');\n" + " return $this->checkResponse($r, $url);\n" + " }\n" + "\n" + " public function enableMaintenanceMode(string $name, string $ip, int $port): bool\n" + " {\n" + " $url = $this->baseUrl . '/v1/agent/service/maintenance/' . $this->getServiceId(\n" + " $name,\n" + " $ip,\n" + " $port\n" + " );\n" + " $r = request($url, 'PUT');\n" + " return $this->checkResponse($r, $url);\n" + " }\n" + "\n" + " public function getCluster(string $name): ?Cluster\n" + " {\n" + " $url = $this->baseUrl . '/v1/catalog/service/' . $this->prefix . $name;\n" + " $r = get($url);\n" + " if (!$this->checkResponse($r, $url)) {\n" + " return null;\n" + " }\n" + " $list = json_decode($r->getBody());\n" + " if (empty($list)) {\n" + " return null;\n" + " }\n" + " $cluster = new Cluster();\n" + " foreach ($list as $li) {\n" + " $cluster->add($li->ServiceAddress, $li->ServicePort, $li->ServiceWeights->Passing);\n" + " }\n" + " return $cluster;\n" + " }\n" + "\n" + " private function getServiceId(string $name, string $ip, int $port): string\n" + " {\n" + " return $this->prefix . $name . \"_{$ip}:{$port}\";\n" + " }\n" + "}\n"; + static const char* swoole_library_source_core_coroutine_functions = "\n" "\n" @@ -7988,6 +8606,31 @@ static const char* swoole_library_source_functions = " }\n" "}\n" "\n" + "class SwooleLibrary\n" + "{\n" + " public static $options = [];\n" + "}\n" + "\n" + "function swoole_library_set_options(array $options)\n" + "{\n" + " SwooleLibrary::$options = $options;\n" + "}\n" + "\n" + "function swoole_library_get_options()\n" + "{\n" + " return SwooleLibrary::$options;\n" + "}\n" + "\n" + "function swoole_library_set_option(string $key, $value)\n" + "{\n" + " SwooleLibrary::$options[$key] = $value;\n" + "}\n" + "\n" + "function swoole_library_get_option(string $key)\n" + "{\n" + " return SwooleLibrary::$options[$key] ?? null;\n" + "}\n" + "\n" "function swoole_string(string $string = ''): Swoole\\StringObject\n" "{\n" " return new Swoole\\StringObject($string);\n" @@ -8135,6 +8778,7 @@ void php_swoole_load_library() zend::eval(swoole_library_source_core_coroutine_server, "@swoole-src/library/core/Coroutine/Server.php"); zend::eval(swoole_library_source_core_coroutine_server_connection, "@swoole-src/library/core/Coroutine/Server/Connection.php"); zend::eval(swoole_library_source_core_coroutine_barrier, "@swoole-src/library/core/Coroutine/Barrier.php"); + zend::eval(swoole_library_source_core_coroutine_http_client_proxy, "@swoole-src/library/core/Coroutine/Http/ClientProxy.php"); zend::eval(swoole_library_source_core_coroutine_http_functions, "@swoole-src/library/core/Coroutine/Http/functions.php"); zend::eval(swoole_library_source_core_connection_pool, "@swoole-src/library/core/ConnectionPool.php"); zend::eval(swoole_library_source_core_database_object_proxy, "@swoole-src/library/core/Database/ObjectProxy.php"); @@ -8177,6 +8821,12 @@ void php_swoole_load_library() zend::eval(swoole_library_source_core_process_manager, "@swoole-src/library/core/Process/Manager.php"); zend::eval(swoole_library_source_core_server_admin, "@swoole-src/library/core/Server/Admin.php"); zend::eval(swoole_library_source_core_server_helper, "@swoole-src/library/core/Server/Helper.php"); + zend::eval(swoole_library_source_core_name_resolver, "@swoole-src/library/core/NameResolver.php"); + zend::eval(swoole_library_source_core_name_resolver_exception, "@swoole-src/library/core/NameResolver/Exception.php"); + zend::eval(swoole_library_source_core_name_resolver_cluster, "@swoole-src/library/core/NameResolver/Cluster.php"); + zend::eval(swoole_library_source_core_name_resolver_redis, "@swoole-src/library/core/NameResolver/Redis.php"); + zend::eval(swoole_library_source_core_name_resolver_nacos, "@swoole-src/library/core/NameResolver/Nacos.php"); + zend::eval(swoole_library_source_core_name_resolver_consul, "@swoole-src/library/core/NameResolver/Consul.php"); zend::eval(swoole_library_source_core_coroutine_functions, "@swoole-src/library/core/Coroutine/functions.php"); zend::eval(swoole_library_source_ext_curl, "@swoole-src/library/ext/curl.php"); zend::eval(swoole_library_source_ext_sockets, "@swoole-src/library/ext/sockets.php"); diff --git a/include/swoole_version.h b/include/swoole_version.h index 312111a439a..fd637f7371c 100644 --- a/include/swoole_version.h +++ b/include/swoole_version.h @@ -21,8 +21,8 @@ #define SWOOLE_MAJOR_VERSION 4 #define SWOOLE_MINOR_VERSION 8 #define SWOOLE_RELEASE_VERSION 2 -#define SWOOLE_EXTRA_VERSION "dev" -#define SWOOLE_VERSION "4.8.2-dev" +#define SWOOLE_EXTRA_VERSION "" +#define SWOOLE_VERSION "4.8.2" #define SWOOLE_VERSION_ID 40802 #define SWOOLE_API_VERSION_ID 0x202109a diff --git a/package.xml b/package.xml index 341d6dcbf99..f11814fa684 100644 --- a/package.xml +++ b/package.xml @@ -51,10 +51,10 @@ doubaokun@php.net yes - 2021-10-27 - + 2021-11-17 + - 4.8.1 + 4.8.2 4.0 @@ -63,27 +63,14 @@ Apache2.0 - New APIs - --- - * Added swoole_error_log_ex(), swoole_ignore_error() (#4440) (@matyhtf) - - Enhancement - --- - * Migrate admin api from ext-swoole_plus to swoole-src (#4441) (@matyhtf) - * Added get_composer_packages command for admin server (swoole/library@07763f46) (swoole/library@8805dc05) (swoole/library@175f1797) (@sy-records) (@yunbaoi) - * Added POST method request restrictions for write operations (swoole/library@ac16927c) (@yunbaoi) - * Supported to get the method information of the class by get_function_info (swoole/library@690a1952) (@djw1028769140) (@sy-records) - * Optimized admin server code (swoole/library#128) (swoole/library#131) (@sy-records) - * Supported to request multiple groups of server information for admin server (swoole/library#124) (@sy-records) - * Supported to get interface info for admin server (swoole/library#130) (@sy-records) - * Supported CURLOPT_HTTPPROXYTUNNEL for SWOOLE_HOOK_CURL (swoole/library#126) (@sy-records) - - Fixed - --- - * Prohibit coroutine concurrent join (#4442) (@matyhtf) - * Fixed init_row, don't clear lock_ and lock_pid (#4446) (@Txhua) (@matyhtf) - * Fixed missing helper options (swoole/library#123) (@sy-records) - * Fixed get_static_property_value command error (swoole/library#129) (@sy-records) + - Fixed memory leak of proc_open hook + - Fixed compatibility of curl native hook with PHP-8.0 and PHP-8.1 + - Fixed connection cannot be closed normally in the Manager process + - Fixed Manager process cannot use sendMessage + - Fixed Coroutine\Http\Server received abnormally large POST data parsing + - Fixed cannot exit directly when a fatal error occurs in PHP8 environment + - Adjust coroutine max_concurrency option, only allowed to be used in Co::set() + - Adjust Coroutine::join() to ignore non-exists coroutine @@ -993,6 +980,9 @@ + + + @@ -1129,6 +1119,7 @@ + @@ -1153,6 +1144,14 @@ + + + + + + + + @@ -1368,6 +1367,8 @@ + + @@ -1414,6 +1415,7 @@ + @@ -1703,6 +1705,7 @@ + @@ -1794,6 +1797,7 @@ + @@ -2099,6 +2103,7 @@ + @@ -2133,7 +2138,6 @@ - @@ -2163,6 +2167,7 @@ + @@ -2171,6 +2176,7 @@ + diff --git a/tools/build-library.php b/tools/build-library.php index 868aae451e6..13c1e39b049 100755 --- a/tools/build-library.php +++ b/tools/build-library.php @@ -33,6 +33,7 @@ 'core/Coroutine/Server.php', 'core/Coroutine/Server/Connection.php', 'core/Coroutine/Barrier.php', + 'core/Coroutine/Http/ClientProxy.php', 'core/Coroutine/Http/functions.php', # # 'core/ConnectionPool.php', @@ -81,6 +82,13 @@ # # 'core/Server/Admin.php', 'core/Server/Helper.php', + # # + 'core/NameResolver.php', + 'core/NameResolver/Exception.php', + 'core/NameResolver/Cluster.php', + 'core/NameResolver/Redis.php', + 'core/NameResolver/Nacos.php', + 'core/NameResolver/Consul.php', # # 'core/Coroutine/functions.php', # #