From 74f0d2fdc52cf4a5a4655db8d00b3938a3e91209 Mon Sep 17 00:00:00 2001 From: Bill Li <21023027+lilianjin@users.noreply.github.com> Date: Mon, 27 Jan 2020 23:38:13 +0800 Subject: [PATCH 01/62] There is no session option on 5.8, so fix it --- src/Websocket/Middleware/StartSession.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Websocket/Middleware/StartSession.php b/src/Websocket/Middleware/StartSession.php index a487f237..6be32c6d 100644 --- a/src/Websocket/Middleware/StartSession.php +++ b/src/Websocket/Middleware/StartSession.php @@ -86,6 +86,6 @@ public function getSession(Request $request) */ protected function sessionConfigured() { - return Arr::get($this->manager->getSessionConfig(), 'session') !== null; + return ! is_null($this->manager->getSessionConfig()['driver'] ?? null); } } From 3cf0cd997d0503f1cc73c8d330818b81dadd6f95 Mon Sep 17 00:00:00 2001 From: Gene Chen Date: Tue, 3 Mar 2020 13:17:17 -0800 Subject: [PATCH 02/62] Clear context after disabling sandbox --- src/Server/Sandbox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server/Sandbox.php b/src/Server/Sandbox.php index 5bf878e1..1fcad3bd 100644 --- a/src/Server/Sandbox.php +++ b/src/Server/Sandbox.php @@ -324,8 +324,8 @@ public function enable() */ public function disable() { - Context::clear(); $this->setInstance($this->getBaseApp()); + Context::clear(); } /** From 5a5c359343ca1b5a99502ad9a6ff869ed3278176 Mon Sep 17 00:00:00 2001 From: Mahdi Youseftabar Date: Tue, 10 Mar 2020 03:52:09 +0330 Subject: [PATCH 03/62] change status() to getStatusCode() laravel response has getStatusCode in all response objects but baniry response has not status() method fixes !289 --- src/Server/AccessOutput.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Server/AccessOutput.php b/src/Server/AccessOutput.php index 08056981..08de5046 100644 --- a/src/Server/AccessOutput.php +++ b/src/Server/AccessOutput.php @@ -41,7 +41,7 @@ public function log(Request $request, Response $response): void $method = $request->method(); $agent = $request->userAgent(); $date = $this->date($response->getDate()); - $status = $response->status(); + $status = $response->getStatusCode(); $style = $this->style($status); $this->output->writeln( @@ -68,4 +68,4 @@ protected function style(int $status): string { return $status !== Response::HTTP_OK ? 'error' : 'info'; } -} \ No newline at end of file +} From 7e815ae999ba10a2dfe31379fb1be85e2a82aefa Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 10 Mar 2020 20:05:29 +0300 Subject: [PATCH 04/62] Update composer.json --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 4e7f11f1..8946791e 100644 --- a/composer.json +++ b/composer.json @@ -22,14 +22,14 @@ ], "require": { "php": "^7.2", - "illuminate/console": "~5.4|~6.0", - "illuminate/contracts": "~5.4|~6.0", - "illuminate/http": "~5.4|~6.0", - "illuminate/support": "~5.4|~6.0", + "illuminate/console": "~5.4|~6.0|~7.0", + "illuminate/contracts": "~5.4|~6.0|~7.0", + "illuminate/http": "~5.4|~6.0|~7.0", + "illuminate/support": "~5.4|~6.0|~7.0", "predis/predis": "^1.1" }, "require-dev": { - "laravel/lumen-framework": "~5.4|~6.0", + "laravel/lumen-framework": "~5.4|~6.0|~7.0", "phpunit/phpunit": "^7.5", "phpunit/php-code-coverage": "^6.1", "php-coveralls/php-coveralls": "^2.1", From 7db04ae00f297985efa72869186408d065049611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=81=A5?= Date: Thu, 7 May 2020 10:42:14 +0800 Subject: [PATCH 05/62] fix 'swoole_set_process_name' not found error on cygwin platform --- src/Helpers/OS.php | 9 ++++++++- src/Server/Manager.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Helpers/OS.php b/src/Helpers/OS.php index d1541639..7a22a6fb 100644 --- a/src/Helpers/OS.php +++ b/src/Helpers/OS.php @@ -30,6 +30,13 @@ final class OS */ public const WIN = 'win'; + /** + * Cygwin + * + * @const string + */ + public const CYGWIN = 'cyg'; + /** * Returns true if current OS in types * @@ -51,4 +58,4 @@ public static function current(): string { return Str::substr(Str::lower(PHP_OS), 0, 3); } -} \ No newline at end of file +} diff --git a/src/Server/Manager.php b/src/Server/Manager.php index 0f751cf6..35e0c9c7 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -353,7 +353,7 @@ protected function clearCache() protected function setProcessName($process) { // MacOS doesn't support modifying process name. - if (OS::is(OS::MAC_OS) || $this->isInTesting()) { + if (OS::is(OS::MAC_OS, OS::CYGWIN) || $this->isInTesting()) { return; } $serverName = 'swoole_http_server'; From 1d5aef72754fdee94779e9ba761a51e89567d33a Mon Sep 17 00:00:00 2001 From: Joe Jiang Date: Mon, 11 May 2020 18:55:36 +0800 Subject: [PATCH 06/62] fix: change MimeType::get condition If pass empty string to this function, It should not return all mimes. --- src/Helpers/MimeType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helpers/MimeType.php b/src/Helpers/MimeType.php index 5edab5cf..7132b629 100644 --- a/src/Helpers/MimeType.php +++ b/src/Helpers/MimeType.php @@ -805,7 +805,7 @@ public static function from($filename) */ public static function get($extension = null) { - return $extension ? self::getMimeTypeFromExtension($extension) : self::$mimes; + return isset($extension) ? self::getMimeTypeFromExtension($extension) : self::$mimes; } /** From 42af646f484862c0f9e2b52eea67568c6eb57070 Mon Sep 17 00:00:00 2001 From: Joe Jiang Date: Mon, 11 May 2020 18:58:37 +0800 Subject: [PATCH 07/62] feat: Add test for empty string to MimeType::get --- tests/Helpers/MimeTypeTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Helpers/MimeTypeTest.php b/tests/Helpers/MimeTypeTest.php index fe8c031d..1dd9e7dd 100644 --- a/tests/Helpers/MimeTypeTest.php +++ b/tests/Helpers/MimeTypeTest.php @@ -14,6 +14,14 @@ public function testGet() $this->assertEquals($mimetype, 'text/css'); } + + public function testGetWithEmptyString() + { + $extension = ''; + $mimetype = MimeType::get($extension); + + $this->assertEquals($mimetype, 'application/octet-stream'); + } public function testFrom() { From 9bce1c29e11a5a1bf6a7f93fc5d40cf42e612a00 Mon Sep 17 00:00:00 2001 From: Linc70J <31087557+Linc70J@users.noreply.github.com> Date: Wed, 13 May 2020 15:48:21 +0800 Subject: [PATCH 08/62] fix handle_static_files config path fix handle_static_files config path --- src/Server/Manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server/Manager.php b/src/Server/Manager.php index 0f751cf6..ec418120 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -204,7 +204,7 @@ public function onRequest($swooleRequest, $swooleResponse) $this->resetOnRequest(); $sandbox = $this->app->make(Sandbox::class); - $handleStatic = $this->container->make('config')->get('swoole_http.handle_static_files', true); + $handleStatic = $this->container->make('config')->get('swoole_http.server.handle_static_files', true); $publicPath = $this->container->make('config')->get('swoole_http.server.public_path', base_path('public')); try { From e9de2aa7c1bba2c344c59de82a6c94b631174b51 Mon Sep 17 00:00:00 2001 From: netdown Date: Thu, 28 May 2020 12:52:37 +0200 Subject: [PATCH 09/62] Replace FatalThrowableError --- src/Server/Manager.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Server/Manager.php b/src/Server/Manager.php index 0f751cf6..e6505381 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -23,7 +23,7 @@ use Symfony\Component\Console\Output\ConsoleOutput; use SwooleTW\Http\Concerns\InteractsWithSwooleQueue; use SwooleTW\Http\Concerns\InteractsWithSwooleTable; -use Symfony\Component\Debug\Exception\FatalThrowableError; +use Symfony\Component\ErrorHandler\Error\FatalError; /** * Class Manager @@ -411,7 +411,23 @@ public function logServerError(Throwable $e) protected function normalizeException(Throwable $e) { if (! $e instanceof Exception) { - $e = new FatalThrowableError($e); + if ($e instanceof \ParseError) { + $severity = E_PARSE; + } elseif ($e instanceof \TypeError) { + $severity = E_RECOVERABLE_ERROR; + } else { + $severity = E_ERROR; + } + + //error_get_last() syntax + $error = [ + 'type' => $severity, + 'message' => $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine(), + ]; + + $e = new FatalError($e->getMessage(), $e->getCode(), $error, null, true, $e->getTrace()); } return $e; From c61511d9918f2440bfbd106d3e466637a5aed315 Mon Sep 17 00:00:00 2001 From: netdown Date: Mon, 8 Jun 2020 13:47:40 +0200 Subject: [PATCH 10/62] Update Websocket.php --- src/Websocket/Websocket.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Websocket/Websocket.php b/src/Websocket/Websocket.php index aa9c45bb..41f05494 100644 --- a/src/Websocket/Websocket.php +++ b/src/Websocket/Websocket.php @@ -170,6 +170,7 @@ public function emit(string $event, $data): bool // that means trying to emit to a non-existing room // skip it directly instead of pushing to a task queue if (empty($fds) && $assigned) { + $this->reset(); return false; } From d80e47f013dc71b277661971be47109a364c9664 Mon Sep 17 00:00:00 2001 From: netdown Date: Mon, 8 Jun 2020 13:59:41 +0200 Subject: [PATCH 11/62] Restore other changes --- src/Server/Manager.php | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/Server/Manager.php b/src/Server/Manager.php index e6505381..0f751cf6 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -23,7 +23,7 @@ use Symfony\Component\Console\Output\ConsoleOutput; use SwooleTW\Http\Concerns\InteractsWithSwooleQueue; use SwooleTW\Http\Concerns\InteractsWithSwooleTable; -use Symfony\Component\ErrorHandler\Error\FatalError; +use Symfony\Component\Debug\Exception\FatalThrowableError; /** * Class Manager @@ -411,23 +411,7 @@ public function logServerError(Throwable $e) protected function normalizeException(Throwable $e) { if (! $e instanceof Exception) { - if ($e instanceof \ParseError) { - $severity = E_PARSE; - } elseif ($e instanceof \TypeError) { - $severity = E_RECOVERABLE_ERROR; - } else { - $severity = E_ERROR; - } - - //error_get_last() syntax - $error = [ - 'type' => $severity, - 'message' => $e->getMessage(), - 'file' => $e->getFile(), - 'line' => $e->getLine(), - ]; - - $e = new FatalError($e->getMessage(), $e->getCode(), $error, null, true, $e->getTrace()); + $e = new FatalThrowableError($e); } return $e; From fda0a045e62690b6fd0d9f479b1267cdcc548839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E6=98=AF=E7=84=B6?= <38133602+icecho@users.noreply.github.com> Date: Tue, 16 Jun 2020 09:55:12 +0800 Subject: [PATCH 12/62] fix a spelling error --- src/Websocket/Rooms/RedisRoom.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Websocket/Rooms/RedisRoom.php b/src/Websocket/Rooms/RedisRoom.php index 365b0b25..46ef7e9b 100644 --- a/src/Websocket/Rooms/RedisRoom.php +++ b/src/Websocket/Rooms/RedisRoom.php @@ -149,7 +149,7 @@ public function addValue($key, array $values, string $table) } /** - * Remove value from reddis. + * Remove value from redis. * * @param $key * @param array $values From bb7b89089e786a527ffc5b68964a69de7ac78068 Mon Sep 17 00:00:00 2001 From: Haven Shen Date: Thu, 23 Jul 2020 14:32:22 +0800 Subject: [PATCH 13/62] modify Dumper.php file class name. --- src/Helpers/Dumper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Helpers/Dumper.php b/src/Helpers/Dumper.php index c4ffb68b..c1087e93 100644 --- a/src/Helpers/Dumper.php +++ b/src/Helpers/Dumper.php @@ -6,7 +6,7 @@ use Symfony\Component\VarDumper\Dumper\CliDumper; use Symfony\Component\VarDumper\Dumper\HtmlDumper; -class VarDumper +class Dumper { protected static $cloner; From 7dc0963662b0fa79258e146d40e379966cc2a84b Mon Sep 17 00:00:00 2001 From: Dawid Janik Date: Tue, 8 Sep 2020 23:14:26 +0200 Subject: [PATCH 14/62] Add Laravel 8 support. --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 8946791e..931c8ecb 100644 --- a/composer.json +++ b/composer.json @@ -22,14 +22,14 @@ ], "require": { "php": "^7.2", - "illuminate/console": "~5.4|~6.0|~7.0", - "illuminate/contracts": "~5.4|~6.0|~7.0", - "illuminate/http": "~5.4|~6.0|~7.0", - "illuminate/support": "~5.4|~6.0|~7.0", + "illuminate/console": "~5.4|~6.0|~7.0|~8.0", + "illuminate/contracts": "~5.4|~6.0|~7.0|~8.0", + "illuminate/http": "~5.4|~6.0|~7.0|~8.0", + "illuminate/support": "~5.4|~6.0|~7.0|~8.0", "predis/predis": "^1.1" }, "require-dev": { - "laravel/lumen-framework": "~5.4|~6.0|~7.0", + "laravel/lumen-framework": "~5.4|~6.0|~7.0|~8.0", "phpunit/phpunit": "^7.5", "phpunit/php-code-coverage": "^6.1", "php-coveralls/php-coveralls": "^2.1", From 3a93e92c8b8ad5eed8bbdf4398faa22bdef48b4f Mon Sep 17 00:00:00 2001 From: Victor Gazotti Date: Thu, 1 Oct 2020 18:35:48 -0300 Subject: [PATCH 15/62] Add auth to the pre_resolved as default As many apps uses the **auth** instances, it could be usefull if auth was cleaned at every request as default. I do this change in every new installation of this package for example. --- config/swoole_http.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/swoole_http.php b/config/swoole_http.php index f73a2c59..150e680f 100644 --- a/config/swoole_http.php +++ b/config/swoole_http.php @@ -81,7 +81,7 @@ 'pre_resolved' => [ 'view', 'files', 'session', 'session.store', 'routes', 'db', 'db.factory', 'cache', 'cache.store', 'config', 'cookie', - 'encrypter', 'hash', 'router', 'translator', 'url', 'log', + 'encrypter', 'hash', 'router', 'translator', 'url', 'log', 'auth', ], /* From b3e824ade8141409543a41976108b275d4a79d3c Mon Sep 17 00:00:00 2001 From: m3m0r7 Date: Tue, 24 Nov 2020 15:05:27 +0900 Subject: [PATCH 16/62] Fix invalid SWOOLE_PROCESS value --- src/Server/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server/helpers.php b/src/Server/helpers.php index 51dd9fcb..f9c43ba8 100644 --- a/src/Server/helpers.php +++ b/src/Server/helpers.php @@ -18,5 +18,5 @@ function swoole_cpu_num(): int } if (! defined('SWOOLE_PROCESS')) { - define('SWOOLE_PROCESS', 3); + define('SWOOLE_PROCESS', 2); } From 2d3c0f92f17ef3c111f1a041bd385ff4d9cd3028 Mon Sep 17 00:00:00 2001 From: Tommie Lagerroos Date: Sun, 29 Nov 2020 14:40:00 +0100 Subject: [PATCH 17/62] Reverted missing fixes PR #417 on FatalThrowableError missing --- src/Server/Manager.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Server/Manager.php b/src/Server/Manager.php index 0495aba1..7f13f862 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -23,7 +23,7 @@ use Symfony\Component\Console\Output\ConsoleOutput; use SwooleTW\Http\Concerns\InteractsWithSwooleQueue; use SwooleTW\Http\Concerns\InteractsWithSwooleTable; -use Symfony\Component\Debug\Exception\FatalThrowableError; +use Symfony\Component\ErrorHandler\Error\FatalError; /** * Class Manager @@ -411,7 +411,22 @@ public function logServerError(Throwable $e) protected function normalizeException(Throwable $e) { if (! $e instanceof Exception) { - $e = new FatalThrowableError($e); + if ($e instanceof \ParseError) { + $severity = E_PARSE; + } elseif ($e instanceof \TypeError) { + $severity = E_RECOVERABLE_ERROR; + } else { + $severity = E_ERROR; + } + + $error = [ + 'type' => $severity, + 'message' => $e->getMessage(), + 'file' => $e->getFile(), + 'line' => $e->getLine(), + ]; + + $e = new FatalError($e->getMessage(), $e->getCode(), $error, null, true, $e->getTrace()); } return $e; From 68104d2a180ce2d30da7db5ab061de679a9c91b5 Mon Sep 17 00:00:00 2001 From: Tommie Lagerroos Date: Sun, 29 Nov 2020 14:42:48 +0100 Subject: [PATCH 18/62] Changed namespace for composer native installation --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 931c8ecb..b4e7443b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "swooletw/laravel-swoole", + "name": "lagerroos/laravel-swoole", "description": "High performance HTTP server based on Swoole. Speed up your Laravel and Lumen applications.", "keywords": [ "swoole", From cd50a39b2896f46924b5479aedbb6954e1d12fa3 Mon Sep 17 00:00:00 2001 From: Zachary He Date: Fri, 4 Dec 2020 18:57:49 +1100 Subject: [PATCH 19/62] Add Gzip support on chunk --- src/Server/Manager.php | 4 +-- src/Transformers/Response.php | 54 +++++++++++++++++++++++++++-- tests/Transformers/ResponseTest.php | 7 ++-- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/Server/Manager.php b/src/Server/Manager.php index 0495aba1..26fe2f69 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -225,7 +225,7 @@ public function onRequest($swooleRequest, $swooleResponse) $illuminateResponse = $sandbox->run($illuminateRequest); // send response - Response::make($illuminateResponse, $swooleResponse)->send(); + Response::make($illuminateResponse, $swooleResponse, $swooleRequest)->send(); } catch (Throwable $e) { try { $exceptionResponse = $this->app @@ -234,7 +234,7 @@ public function onRequest($swooleRequest, $swooleResponse) $illuminateRequest, $this->normalizeException($e) ); - Response::make($exceptionResponse, $swooleResponse)->send(); + Response::make($exceptionResponse, $swooleResponse, $swooleRequest)->send(); } catch (Throwable $e) { $this->logServerError($e); } diff --git a/src/Transformers/Response.php b/src/Transformers/Response.php index 416a26fa..da9a0228 100644 --- a/src/Transformers/Response.php +++ b/src/Transformers/Response.php @@ -4,6 +4,7 @@ use Illuminate\Http\Response as IlluminateResponse; use Swoole\Http\Response as SwooleResponse; +use Swoole\Http\Request as SwooleRequest; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -17,6 +18,11 @@ class Response */ protected $swooleResponse; + /** + * @var \Swoole\Http\Request + */ + protected $swooleRequest; + /** * @var \Illuminate\Http\Response */ @@ -27,12 +33,13 @@ class Response * * @param $illuminateResponse * @param \Swoole\Http\Response $swooleResponse + * @param \Swoole\Http\Request $swooleRequest * * @return \SwooleTW\Http\Transformers\Response */ - public static function make($illuminateResponse, SwooleResponse $swooleResponse) + public static function make($illuminateResponse, SwooleResponse $swooleResponse, SwooleRequest $swooleRequest) { - return new static($illuminateResponse, $swooleResponse); + return new static($illuminateResponse, $swooleResponse, $swooleRequest); } /** @@ -40,11 +47,13 @@ public static function make($illuminateResponse, SwooleResponse $swooleResponse) * * @param mixed $illuminateResponse * @param \Swoole\Http\Response $swooleResponse + * @param \Swoole\Http\Request $swooleRequest */ - public function __construct($illuminateResponse, SwooleResponse $swooleResponse) + public function __construct($illuminateResponse, SwooleResponse $swooleResponse, SwooleRequest $swooleRequest) { $this->setIlluminateResponse($illuminateResponse); $this->setSwooleResponse($swooleResponse); + $this->setSwooleRequest($swooleRequest); } /** @@ -133,6 +142,12 @@ protected function sendInChunk($content) return; } + // Swoole Chunk mode does not support compress by default, this patch only supports gzip + if ($chunkGzip) { + $this->swooleResponse->header('Content-Encoding', 'gzip'); + $content = gzencode($content, config('swoole_http.server.options.http_compression_level', 3)); + } + foreach (str_split($content, static::CHUNK_SIZE) as $chunk) { $this->swooleResponse->write($chunk); } @@ -184,4 +199,37 @@ public function getIlluminateResponse() { return $this->illuminateResponse; } + + /** + * @param \Swoole\Http\Request $swooleRequest + * + * @return \SwooleTW\Http\Transformers\Response + */ + protected function setSwooleRequest(SwooleRequest $swooleRequest) + { + $this->swooleRequest = $swooleRequest; + + return $this; + } + + /** + * @return \Swoole\Http\Request + */ + public function getSwooleRequest() + { + return $this->swooleRequest; + } + + /** + * @param string $responseContentEncoding + * @return bool + */ + protected function canGzipContent($responseContentEncoding) + { + return empty($responseContentEncoding) && + config('swoole_http.server.options.http_compression', true) && + !empty($this->swooleRequest->header['accept-encoding']) && + strpos($this->swooleRequest->header['accept-encoding'], 'gzip') !== false && + function_exists('gzencode'); + } } diff --git a/tests/Transformers/ResponseTest.php b/tests/Transformers/ResponseTest.php index 41df5999..6b24d72c 100644 --- a/tests/Transformers/ResponseTest.php +++ b/tests/Transformers/ResponseTest.php @@ -4,6 +4,7 @@ use Illuminate\Http\Response as IlluminateResponse; use Swoole\Http\Response as SwooleResponse; +use Swoole\Http\Request as SwooleRequest; use SwooleTW\Http\Tests\TestCase; use SwooleTW\Http\Transformers\Response; @@ -11,14 +12,14 @@ class ResponseTest extends TestCase { public function testMake() { - $response = Response::make(new IlluminateResponse, new SwooleResponse); + $response = Response::make(new IlluminateResponse, new SwooleResponse, new SwooleRequest); $this->assertInstanceOf(Response::class, $response); } public function testGetIlluminateResponse() { - $response = Response::make(new IlluminateResponse, new SwooleResponse); + $response = Response::make(new IlluminateResponse, new SwooleResponse, new SwooleRequest); $illuminateResponse = $response->getIlluminateResponse(); $this->assertInstanceOf(IlluminateResponse::class, $illuminateResponse); @@ -26,7 +27,7 @@ public function testGetIlluminateResponse() public function testGetSwooleResponse() { - $response = Response::make(new IlluminateResponse, new SwooleResponse); + $response = Response::make(new IlluminateResponse, new SwooleResponse, new SwooleRequest); $swooleResponse = $response->getSwooleResponse(); $this->assertInstanceOf(SwooleResponse::class, $swooleResponse); From c350158453dfea21815d84ad9d732296fff0fc43 Mon Sep 17 00:00:00 2001 From: Zachary He Date: Fri, 4 Dec 2020 19:07:52 +1100 Subject: [PATCH 20/62] add condition in --- src/Transformers/Response.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Transformers/Response.php b/src/Transformers/Response.php index da9a0228..6a73856f 100644 --- a/src/Transformers/Response.php +++ b/src/Transformers/Response.php @@ -126,6 +126,7 @@ protected function sendContent() } elseif ($illuminateResponse instanceof BinaryFileResponse) { $this->swooleResponse->sendfile($illuminateResponse->getFile()->getPathname()); } else { + $chunkGzip = $this->canGzipContent($illuminateResponse->headers->get('Content-Encoding')); $this->sendInChunk($illuminateResponse->getContent()); } } From 2911def74d9f9f9e138c53748f769cc352b3a2a3 Mon Sep 17 00:00:00 2001 From: Zachary He Date: Fri, 4 Dec 2020 19:12:01 +1100 Subject: [PATCH 21/62] forgot to update method --- src/Transformers/Response.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Transformers/Response.php b/src/Transformers/Response.php index 6a73856f..157d6f33 100644 --- a/src/Transformers/Response.php +++ b/src/Transformers/Response.php @@ -127,7 +127,7 @@ protected function sendContent() $this->swooleResponse->sendfile($illuminateResponse->getFile()->getPathname()); } else { $chunkGzip = $this->canGzipContent($illuminateResponse->headers->get('Content-Encoding')); - $this->sendInChunk($illuminateResponse->getContent()); + $this->sendInChunk($illuminateResponse->getContent(), $chunkGzip); } } @@ -135,8 +135,9 @@ protected function sendContent() * Send content in chunk * * @param string $content + * @param bool $chunkGzip */ - protected function sendInChunk($content) + protected function sendInChunk($content, $chunkGzip) { if (strlen($content) <= static::CHUNK_SIZE) { $this->swooleResponse->end($content); From b2da17030c05710112777e1a992b1ff2d768b820 Mon Sep 17 00:00:00 2001 From: Zachary He Date: Thu, 17 Dec 2020 12:48:50 +1100 Subject: [PATCH 22/62] Add test case for Response --- tests/Transformers/ResponseTest.php | 276 ++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+) diff --git a/tests/Transformers/ResponseTest.php b/tests/Transformers/ResponseTest.php index 6b24d72c..03122a10 100644 --- a/tests/Transformers/ResponseTest.php +++ b/tests/Transformers/ResponseTest.php @@ -2,11 +2,18 @@ namespace SwooleTW\Http\Tests\Transformers; +use Symfony\Component\HttpFoundation\ResponseHeaderBag; +use Symfony\Component\HttpFoundation\StreamedResponse; +use Symfony\Component\HttpFoundation\BinaryFileResponse; +use Symfony\Component\HttpFoundation\Cookie; +use Symfony\Component\HttpFoundation\File\File; use Illuminate\Http\Response as IlluminateResponse; +use Illuminate\Support\Str; use Swoole\Http\Response as SwooleResponse; use Swoole\Http\Request as SwooleRequest; use SwooleTW\Http\Tests\TestCase; use SwooleTW\Http\Transformers\Response; +use Mockery; class ResponseTest extends TestCase { @@ -32,4 +39,273 @@ public function testGetSwooleResponse() $this->assertInstanceOf(SwooleResponse::class, $swooleResponse); } + + public function testGetSwooleRequest() + { + $response = Response::make(new IlluminateResponse, new SwooleResponse, new SwooleRequest); + $swooleRequest = $response->getSwooleRequest(); + + $this->assertInstanceOf(SwooleRequest::class, $swooleRequest); + } + + public function testSendHeaders() + { + $headers = ['test' => ['123', '456']]; + $status = 200; + + // rawcookie + $cookie1 = Mockery::mock(Cookie::class); + $cookie1->shouldReceive('isRaw')->once()->andReturn(true); + $cookie1->shouldReceive('getName')->once()->andReturn('Cookie_1_getName'); + $cookie1->shouldReceive('getValue')->once()->andReturn('Cookie_1_getValue'); + $cookie1->shouldReceive('getExpiresTime')->once()->andReturn('Cookie_1_getExpiresTime'); + $cookie1->shouldReceive('getPath')->once()->andReturn('Cookie_1_getPath'); + $cookie1->shouldReceive('getDomain')->once()->andReturn('Cookie_1_getDomain'); + $cookie1->shouldReceive('isSecure')->once()->andReturn('Cookie_1_isSecure'); + $cookie1->shouldReceive('isHttpOnly')->once()->andReturn('Cookie_1_isHttpOnly'); + + // cookie + $cookie2 = Mockery::mock(Cookie::class); + $cookie2->shouldReceive('isRaw')->once()->andReturn(false); + $cookie2->shouldReceive('getName')->once()->andReturn('Cookie_2_getName'); + $cookie2->shouldReceive('getValue')->once()->andReturn('Cookie_2_getValue'); + $cookie2->shouldReceive('getExpiresTime')->once()->andReturn('Cookie_2_getExpiresTime'); + $cookie2->shouldReceive('getPath')->once()->andReturn('Cookie_2_getPath'); + $cookie2->shouldReceive('getDomain')->once()->andReturn('Cookie_2_getDomain'); + $cookie2->shouldReceive('isSecure')->once()->andReturn('Cookie_2_isSecure'); + $cookie2->shouldReceive('isHttpOnly')->once()->andReturn('Cookie_2_isHttpOnly'); + + $illuminateResponse = Mockery::mock(IlluminateResponse::class); + $illuminateResponse->headers = Mockery::mock(ResponseHeaderBag::class); + + $illuminateResponse->headers + ->shouldReceive('has') + ->once() + ->with('Date') + ->andReturn(false); + + $illuminateResponse->headers + ->shouldReceive('getCookies') + ->once() + ->andReturn([$cookie1, $cookie2] ); + + $illuminateResponse->headers + ->shouldReceive('allPreserveCase') + ->once() + ->andReturn([ + 'Set-Cookie' => uniqid(), + ] + $headers); + + $illuminateResponse->shouldReceive('setDate') + ->once() + ->withArgs(function(\DateTime $dateTime) { + $timestamp = $dateTime->getTimestamp(); + return $timestamp <= time() && $timestamp + 2 > time(); + }); + + $illuminateResponse->shouldReceive('getStatusCode') + ->once() + ->andReturn($status); + + $swooleResponse = Mockery::mock(SwooleResponse::class); + $swooleResponse->shouldReceive('header') + ->times(2) + ->withArgs(function ($name, $value) use (&$headers) { + $header = array_shift($headers['test']); + return $name === 'test' && $header === $value; + }); + $swooleResponse->shouldReceive('status') + ->once() + ->withArgs([$status]); + $swooleResponse->shouldReceive('rawcookie') + ->once() + ->withArgs([ + 'Cookie_1_getName', + 'Cookie_1_getValue', + 'Cookie_1_getExpiresTime', + 'Cookie_1_getPath', + 'Cookie_1_getDomain', + 'Cookie_1_isSecure', + 'Cookie_1_isHttpOnly' + ]); + $swooleResponse->shouldReceive('cookie') + ->once() + ->withArgs([ + 'Cookie_2_getName', + 'Cookie_2_getValue', + 'Cookie_2_getExpiresTime', + 'Cookie_2_getPath', + 'Cookie_2_getDomain', + 'Cookie_2_isSecure', + 'Cookie_2_isHttpOnly' + ]); + + $swooleRequest = Mockery::mock(SwooleRequest::class); + + $response = Response::make($illuminateResponse, $swooleResponse, $swooleRequest); + + /** + * use Closure::call to bypass protect and private method + * url: https://www.php.net/manual/en/closure.call.php + */ + $callback = function() { + $this->sendHeaders(); + }; + $callback->call($response); + } + + public function testSendStreamedResponseContent() + { + $illuminateResponse = Mockery::mock(StreamedResponse::class); + $illuminateResponse->output = uniqid(); + + $swooleResponse = Mockery::mock(SwooleResponse::class); + $swooleResponse->shouldReceive('end') + ->once() + ->withArgs([$illuminateResponse->output]); + + $swooleRequest = Mockery::mock(SwooleRequest::class); + + $response = Response::make($illuminateResponse, $swooleResponse, $swooleRequest); + + /** + * use Closure::call to bypass protect and private method + * url: https://www.php.net/manual/en/closure.call.php + */ + $callback = function() { + $this->sendContent(); + }; + $callback->call($response); + } + + public function testSendBinaryFileResponseContent() + { + $path = uniqid(); + $file = Mockery::mock(File::class); + $file->shouldReceive('getPathname') + ->once() + ->andReturn($path); + + $illuminateResponse = Mockery::mock(BinaryFileResponse::class); + $illuminateResponse->shouldReceive('getFile') + ->once() + ->andReturn($file); + + $swooleResponse = Mockery::mock(SwooleResponse::class); + $swooleResponse->shouldReceive('sendfile') + ->once() + ->withArgs([$path]); + + $swooleRequest = Mockery::mock(SwooleRequest::class); + + $response = Response::make($illuminateResponse, $swooleResponse, $swooleRequest); + + /** + * use Closure::call to bypass protect and private method + * url: https://www.php.net/manual/en/closure.call.php + */ + $callback = function() { + $this->sendContent(); + }; + $callback->call($response); + } + + public function testSendChunkedContent() + { + $http_compression_level = 5; + $content = Str::random(Response::CHUNK_SIZE * 3); + $compressedContent = gzencode($content, $http_compression_level); + $times = (int)ceil(strlen($compressedContent) / Response::CHUNK_SIZE); + + $chunks = []; + foreach (str_split($compressedContent, Response::CHUNK_SIZE) as $chunk) { + $chunks[] = $chunk; + } + + app()->instance('config', new \Illuminate\Config\Repository([ + 'swoole_http' => [ + 'server' => [ + 'options' => [ + 'http_compression' => true, + 'http_compression_level' => $http_compression_level + ] + ], + ], + ])); + + $illuminateResponse = Mockery::mock(IlluminateResponse::class); + $illuminateResponse->headers = Mockery::mock(ResponseHeaderBag::class); + + $illuminateResponse->headers + ->shouldReceive('get') + ->once() + ->withArgs(['Content-Encoding']) + ->andReturn(null); + + $illuminateResponse->shouldReceive('getContent') + ->andReturn($content); + + $swooleResponse = Mockery::mock(SwooleResponse::class); + $swooleResponse->shouldReceive('header') + ->once() + ->withArgs(['Content-Encoding', 'gzip']); + + $swooleResponse->shouldReceive('write') + ->times($times) + ->withArgs(function ($chunk) use (&$chunks) { + $expectChunk = array_shift($chunks); + return $chunk === $expectChunk; + }); + $swooleResponse->shouldReceive('end') + ->once(); + + $swooleRequest = Mockery::mock(SwooleRequest::class); + $swooleRequest->header = ['accept-encoding' => 'gzip, deflate, br']; + + $response = Response::make($illuminateResponse, $swooleResponse, $swooleRequest); + + /** + * use Closure::call to bypass protect and private method + * url: https://www.php.net/manual/en/closure.call.php + */ + $callback = function() { + $this->sendContent(); + }; + $callback->call($response); + } + + public function testSend_() + { + $status = 200; + $content = 'test'; + + app()->instance('config', new \Illuminate\Config\Repository([ + 'swoole_http' => [ + 'server' => [ + 'options' => [ + 'http_compression' => false, + ] + ], + ], + ])); + + $swooleResponse = Mockery::mock(SwooleResponse::class); + $swooleResponse->shouldReceive('header') + ->twice() + ->withArgs(function ($name, $value) { + return in_array($name, ['Date', 'Cache-Control'], true); + }); + $swooleResponse->shouldReceive('status') + ->once() + ->with(200); + $swooleResponse->shouldReceive('end') + ->once() + ->withArgs([$content]); + + $swooleRequest = Mockery::mock(SwooleRequest::class); + $swooleRequest->header = ['accept-encoding' => 'gzip, deflate, br']; + + $response = Response::make($content, $swooleResponse, $swooleRequest); + $response->send(); + } } From 9bc3fa8a609bedc849547072a3f13628dcfd0b5f Mon Sep 17 00:00:00 2001 From: Tommie Lagerroos Date: Sun, 3 Jan 2021 18:32:16 +0100 Subject: [PATCH 23/62] Reverted package name change --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b4e7443b..931c8ecb 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "lagerroos/laravel-swoole", + "name": "swooletw/laravel-swoole", "description": "High performance HTTP server based on Swoole. Speed up your Laravel and Lumen applications.", "keywords": [ "swoole", From 428e5d19a32c1bbafd3d934fb5d9de6e84649786 Mon Sep 17 00:00:00 2001 From: Jeroen van Meeuwen Date: Mon, 11 Jan 2021 17:17:21 +0100 Subject: [PATCH 24/62] Attempt to fix directory traversal --- config/swoole_http.php | 2 +- src/Server/Manager.php | 4 ++-- src/Transformers/Request.php | 14 +++++++++++--- tests/Server/ManagerTest.php | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/config/swoole_http.php b/config/swoole_http.php index 150e680f..4eeb878f 100644 --- a/config/swoole_http.php +++ b/config/swoole_http.php @@ -12,7 +12,7 @@ 'server' => [ 'host' => env('SWOOLE_HTTP_HOST', '127.0.0.1'), 'port' => env('SWOOLE_HTTP_PORT', '1215'), - 'public_path' => base_path('public'), + 'document_root' => base_path('public'), // Determine if to use swoole to respond request for static files 'handle_static_files' => env('SWOOLE_HANDLE_STATIC', true), 'access_log' => env('SWOOLE_HTTP_ACCESS_LOG', false), diff --git a/src/Server/Manager.php b/src/Server/Manager.php index 7f13f862..845dc234 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -205,11 +205,11 @@ public function onRequest($swooleRequest, $swooleResponse) $this->resetOnRequest(); $sandbox = $this->app->make(Sandbox::class); $handleStatic = $this->container->make('config')->get('swoole_http.server.handle_static_files', true); - $publicPath = $this->container->make('config')->get('swoole_http.server.public_path', base_path('public')); + $documentRoot = $this->container->make('config')->get('swoole_http.server.document_root', base_path('public')); try { // handle static file request first - if ($handleStatic && Request::handleStatic($swooleRequest, $swooleResponse, $publicPath)) { + if ($handleStatic && Request::handleStatic($swooleRequest, $swooleResponse, $documentRoot)) { return; } // transform swoole request to illuminate request diff --git a/src/Transformers/Request.php b/src/Transformers/Request.php index 1dbd41db..16e4c006 100644 --- a/src/Transformers/Request.php +++ b/src/Transformers/Request.php @@ -175,20 +175,28 @@ protected static function transformServerParameters(array $server, array $header * * @param \Swoole\Http\Request $swooleRequest * @param \Swoole\Http\Response $swooleResponse - * @param string $publicPath + * @param string $documentRoot * * @return boolean */ - public static function handleStatic($swooleRequest, $swooleResponse, string $publicPath) + public static function handleStatic($swooleRequest, $swooleResponse, string $documentRoot) { $uri = $swooleRequest->server['request_uri'] ?? ''; $extension = strtok(pathinfo($uri, PATHINFO_EXTENSION), '?'); - $fileName = $publicPath . $uri; + $fileName = @realpath($documentRoot . $uri); + + if (!$fileName) { + return false; + } if ($extension && in_array($extension, static::EXTENSION_BLACKLIST)) { return false; } + if (substr($fileName, 0, strlen($documentRoot)) != $documentRoot) { + return false; + } + if (! is_file($fileName) || ! filesize($fileName)) { return false; } diff --git a/tests/Server/ManagerTest.php b/tests/Server/ManagerTest.php index 2f56f526..2f2e5901 100644 --- a/tests/Server/ManagerTest.php +++ b/tests/Server/ManagerTest.php @@ -61,7 +61,7 @@ class ManagerTest extends TestCase 'swoole_http.tables' => [], 'swoole_http.providers' => [], 'swoole_http.resetters' => [], - 'swoole_http.server.public_path' => '/', + 'swoole_http.server.document_root' => '/', ]; public function testGetFramework() From 96a93e93b5a97a6aefa6b6dfa5e2b346c9fb4af9 Mon Sep 17 00:00:00 2001 From: Jeroen van Meeuwen Date: Tue, 12 Jan 2021 09:59:04 +0100 Subject: [PATCH 25/62] Remove public path -> document root change --- config/swoole_http.php | 2 +- src/Server/Manager.php | 4 ++-- src/Transformers/Request.php | 8 ++++---- tests/Server/ManagerTest.php | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config/swoole_http.php b/config/swoole_http.php index 4eeb878f..150e680f 100644 --- a/config/swoole_http.php +++ b/config/swoole_http.php @@ -12,7 +12,7 @@ 'server' => [ 'host' => env('SWOOLE_HTTP_HOST', '127.0.0.1'), 'port' => env('SWOOLE_HTTP_PORT', '1215'), - 'document_root' => base_path('public'), + 'public_path' => base_path('public'), // Determine if to use swoole to respond request for static files 'handle_static_files' => env('SWOOLE_HANDLE_STATIC', true), 'access_log' => env('SWOOLE_HTTP_ACCESS_LOG', false), diff --git a/src/Server/Manager.php b/src/Server/Manager.php index 845dc234..7f13f862 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -205,11 +205,11 @@ public function onRequest($swooleRequest, $swooleResponse) $this->resetOnRequest(); $sandbox = $this->app->make(Sandbox::class); $handleStatic = $this->container->make('config')->get('swoole_http.server.handle_static_files', true); - $documentRoot = $this->container->make('config')->get('swoole_http.server.document_root', base_path('public')); + $publicPath = $this->container->make('config')->get('swoole_http.server.public_path', base_path('public')); try { // handle static file request first - if ($handleStatic && Request::handleStatic($swooleRequest, $swooleResponse, $documentRoot)) { + if ($handleStatic && Request::handleStatic($swooleRequest, $swooleResponse, $publicPath)) { return; } // transform swoole request to illuminate request diff --git a/src/Transformers/Request.php b/src/Transformers/Request.php index 16e4c006..791cd156 100644 --- a/src/Transformers/Request.php +++ b/src/Transformers/Request.php @@ -175,15 +175,15 @@ protected static function transformServerParameters(array $server, array $header * * @param \Swoole\Http\Request $swooleRequest * @param \Swoole\Http\Response $swooleResponse - * @param string $documentRoot + * @param string $publicPath * * @return boolean */ - public static function handleStatic($swooleRequest, $swooleResponse, string $documentRoot) + public static function handleStatic($swooleRequest, $swooleResponse, string $publicPath) { $uri = $swooleRequest->server['request_uri'] ?? ''; $extension = strtok(pathinfo($uri, PATHINFO_EXTENSION), '?'); - $fileName = @realpath($documentRoot . $uri); + $fileName = @realpath($publicPath . $uri); if (!$fileName) { return false; @@ -193,7 +193,7 @@ public static function handleStatic($swooleRequest, $swooleResponse, string $doc return false; } - if (substr($fileName, 0, strlen($documentRoot)) != $documentRoot) { + if (substr($fileName, 0, strlen($publicPath)) != $publicPath) { return false; } diff --git a/tests/Server/ManagerTest.php b/tests/Server/ManagerTest.php index 2f2e5901..2f56f526 100644 --- a/tests/Server/ManagerTest.php +++ b/tests/Server/ManagerTest.php @@ -61,7 +61,7 @@ class ManagerTest extends TestCase 'swoole_http.tables' => [], 'swoole_http.providers' => [], 'swoole_http.resetters' => [], - 'swoole_http.server.document_root' => '/', + 'swoole_http.server.public_path' => '/', ]; public function testGetFramework() From 7770f4a22efac43acbc8817f20fcb9460a87df59 Mon Sep 17 00:00:00 2001 From: Chuong Date: Thu, 25 Feb 2021 11:06:41 +0700 Subject: [PATCH 26/62] feat: add hook action for http server allow user to run custom script before starting server up --- src/Commands/HttpServerCommand.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Commands/HttpServerCommand.php b/src/Commands/HttpServerCommand.php index 5ed1d959..df9e0048 100644 --- a/src/Commands/HttpServerCommand.php +++ b/src/Commands/HttpServerCommand.php @@ -70,6 +70,7 @@ public function handle() $this->checkEnvironment(); $this->loadConfigs(); $this->initAction(); + $this->hookAction(); $this->runAction(); } @@ -80,6 +81,14 @@ protected function loadConfigs() { $this->config = $this->laravel->make('config')->get('swoole_http'); } + + /** + * Hook action + */ + protected function hookAction() + { + // custom hook task before starting server + } /** * Run action. From cffa9ee77180b5790b5339debe34c55aa17c0b96 Mon Sep 17 00:00:00 2001 From: Arkanius Date: Mon, 15 Mar 2021 10:11:41 -0300 Subject: [PATCH 27/62] adding support to php8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 931c8ecb..042dde26 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ } ], "require": { - "php": "^7.2", + "php": "^7.2|^8.0", "illuminate/console": "~5.4|~6.0|~7.0|~8.0", "illuminate/contracts": "~5.4|~6.0|~7.0|~8.0", "illuminate/http": "~5.4|~6.0|~7.0|~8.0", From 936769f8747c0702ba75cbf8576fbef58be4254b Mon Sep 17 00:00:00 2001 From: Arkanius Date: Mon, 15 Mar 2021 10:24:57 -0300 Subject: [PATCH 28/62] update travis versiosn --- .travis.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a90e95ac..eb8d97aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,14 +14,28 @@ matrix: env: FRAMEWORK_VERSION=laravel/framework:5.8.* - php: 7.2 env: FRAMEWORK_VERSION=laravel/framework:6.0.* + - php: 7.2 + env: FRAMEWORK_VERSION=laravel/framework:7.0.* + - php: 7.2 + env: FRAMEWORK_VERSION=laravel/framework:8.0.* + - php: 8.0 + env: FRAMEWORK_VERSION=laravel/framework:8.0.* - php: 7.2 env: FRAMEWORK_VERSION=laravel/lumen-framework:5.5.* - php: 7.2 env: FRAMEWORK_VERSION=laravel/lumen-framework:5.6.* - php: 7.2 env: FRAMEWORK_VERSION=laravel/lumen-framework:5.7.* - # - php: 7.2 - # env: FRAMEWORK_VERSION=laravel/lumen-framework:5.8.* + - php: 7.2 + env: FRAMEWORK_VERSION=laravel/lumen-framework:5.8.* + - php: 7.2 + env: FRAMEWORK_VERSION=laravel/lumen-framework:6.0.* + - php: 7.2 + env: FRAMEWORK_VERSION=laravel/lumen-framework:7.0.* + - php: 7.2 + env: FRAMEWORK_VERSION=laravel/lumen-framework:8.0.* + - php: 8.0 + env: FRAMEWORK_VERSION=laravel/lumen-framework:8.0.* before_install: - printf "\n" | pecl install swoole From a42c0168b2660b70e6597d0b23a8dca1f7dae510 Mon Sep 17 00:00:00 2001 From: Liam Hao Date: Fri, 19 Mar 2021 22:40:56 +0800 Subject: [PATCH 29/62] Update Pusher.php add `?string` type to `$message`. This style of function declaration [has been deprecated in PHP 8.0](https://www.php.net/manual/en/migration80.deprecated.php). solve issue: **[Is this a BUG?](https://github.com/swooletw/laravel-swoole/issues/472)** --- src/Websocket/Pusher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Websocket/Pusher.php b/src/Websocket/Pusher.php index 32b8e91f..a5cdc875 100644 --- a/src/Websocket/Pusher.php +++ b/src/Websocket/Pusher.php @@ -68,7 +68,7 @@ protected function __construct( bool $broadcast, bool $assigned, string $event, - $message = null, + ?string $message, $server ) { From f94b69f9073a585349f58dd6490786d14d033a76 Mon Sep 17 00:00:00 2001 From: Victor Gazotti Date: Wed, 24 Mar 2021 09:55:07 -0300 Subject: [PATCH 30/62] Update .travis.yml --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index eb8d97aa..bc4477b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: php dist: trusty sudo: false +env: + global: + - COMPOSER_MEMORY_LIMIT=-1 matrix: include: - php: 7.2 From c17cb490125e459063854bb2d50245bd8a5482b1 Mon Sep 17 00:00:00 2001 From: Victor Gazotti Date: Wed, 24 Mar 2021 09:56:07 -0300 Subject: [PATCH 31/62] Update Pusher.php --- src/Websocket/Pusher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Websocket/Pusher.php b/src/Websocket/Pusher.php index a5cdc875..5d772788 100644 --- a/src/Websocket/Pusher.php +++ b/src/Websocket/Pusher.php @@ -45,7 +45,7 @@ class Pusher protected $event; /** - * @var mixed|null + * @var string|null */ protected $message; From c89542d29a5ca138b3fab916b41d6a6adf4f4df6 Mon Sep 17 00:00:00 2001 From: m3m0r7 Date: Wed, 21 Apr 2021 15:53:07 +0900 Subject: [PATCH 32/62] fix could not working task when enabling task_enable_coroutine on swoole_http.php --- src/Server/Manager.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Server/Manager.php b/src/Server/Manager.php index 39ae7827..930dee10 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -260,11 +260,19 @@ protected function resetOnRequest() * * @param mixed $server * @param string|\Swoole\Server\Task $taskId or $task - * @param string $srcWorkerId - * @param mixed $data + * @param string|null $srcWorkerId + * @param mixed|null $data */ - public function onTask($server, $taskId, $srcWorkerId, $data) + public function onTask($server, $task, $srcWorkerId = null, $data = null) { + if ($task instanceof Task) { + $data = $task->data; + $srcWorkerId = $task->worker_id; + $taskId = $task->id; + } else { + $taskId = $task; + } + $this->container->make('events')->dispatch('swoole.task', func_get_args()); try { From c1f0f9cd8d5dad8ec5d0197ae131416cc08f0235 Mon Sep 17 00:00:00 2001 From: m3m0r7 Date: Wed, 5 May 2021 11:29:45 +0900 Subject: [PATCH 33/62] Reference same coroutine id in same request --- src/Coroutine/Context.php | 18 +++++++++++++++--- tests/Coroutine/ContextTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Coroutine/Context.php b/src/Coroutine/Context.php index 2ea8a20c..29d823b3 100644 --- a/src/Coroutine/Context.php +++ b/src/Coroutine/Context.php @@ -7,6 +7,8 @@ class Context { + protected const MAX_RECURSE_CONTEXT_ID = 50; + /** * The app containers in different coroutine environment. * @@ -90,10 +92,20 @@ public static function clear() } /** - * Get current coroutine id. + * Get current requesting coroutine id. */ - public static function getCoroutineId() + public static function getCoroutineId(): int { - return Coroutine::getuid(); + $currentId = Coroutine::getuid(); + if ($currentId === -1) { + return -1; + } + + $counter = 0; + while (($topCoroutineId = Coroutine::getPcid($currentId)) !== -1 && $counter <= self::MAX_RECURSE_CONTEXT_ID) { + $currentId = $topCoroutineId; + $counter++; + } + return $currentId; } } diff --git a/tests/Coroutine/ContextTest.php b/tests/Coroutine/ContextTest.php index a9ef6800..8e267543 100644 --- a/tests/Coroutine/ContextTest.php +++ b/tests/Coroutine/ContextTest.php @@ -52,6 +52,31 @@ public function testGetDataKeys() $this->assertSame(['foo', 'sea'], Context::getDataKeys()); } + public function testGetDataKeyInCoroutine() + { + $data1 = null; + $data2 = null; + $coroutineId1 = null; + $coroutineId2 = null; + \Swoole\Coroutine\run(function () use (&$data1, &$data2, &$coroutineId1, &$coroutineId2) { + Context::setData('foo', 'bar'); + + $data1 = Context::getData('foo'); + $data2 = 'baz'; + $coroutineId1 = Context::getCoroutineId(); + $coroutineId2 = -1; + + go(function () use (&$data2, &$coroutineId2) { + $data2 = Context::getData('foo'); + $coroutineId2 = Context::getCoroutineId(); + }); + }); + + $this->assertSame('bar', $data1); + $this->assertSame($data1, $data2); + $this->assertSame($coroutineId1, $coroutineId2); + } + public function testClear() { Context::setApp(m::mock(Container::class)); From fffaf16c6f6e7fb35bd4cf064f50b5d481d85a9c Mon Sep 17 00:00:00 2001 From: m3m0r7 Date: Wed, 5 May 2021 11:30:26 +0900 Subject: [PATCH 34/62] Rename const --- src/Coroutine/Context.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Coroutine/Context.php b/src/Coroutine/Context.php index 29d823b3..c88f88a1 100644 --- a/src/Coroutine/Context.php +++ b/src/Coroutine/Context.php @@ -7,7 +7,7 @@ class Context { - protected const MAX_RECURSE_CONTEXT_ID = 50; + protected const MAX_RECURSE_COROUTINE_ID = 50; /** * The app containers in different coroutine environment. @@ -102,7 +102,7 @@ public static function getCoroutineId(): int } $counter = 0; - while (($topCoroutineId = Coroutine::getPcid($currentId)) !== -1 && $counter <= self::MAX_RECURSE_CONTEXT_ID) { + while (($topCoroutineId = Coroutine::getPcid($currentId)) !== -1 && $counter <= self::MAX_RECURSE_COROUTINE_ID) { $currentId = $topCoroutineId; $counter++; } From fd75cd3cbbe10a0741d1060545e94cae46fa700a Mon Sep 17 00:00:00 2001 From: m3m0r7 Date: Wed, 5 May 2021 11:44:04 +0900 Subject: [PATCH 35/62] Refactor --- src/Coroutine/Context.php | 29 +++++++++++++++++------------ tests/Coroutine/ContextTest.php | 4 ++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Coroutine/Context.php b/src/Coroutine/Context.php index c88f88a1..3117ef55 100644 --- a/src/Coroutine/Context.php +++ b/src/Coroutine/Context.php @@ -28,7 +28,7 @@ class Context */ public static function getApp() { - return static::$apps[static::getCoroutineId()] ?? null; + return static::$apps[static::getRequestedCoroutineId()] ?? null; } /** @@ -38,7 +38,7 @@ public static function getApp() */ public static function setApp(Container $app) { - static::$apps[static::getCoroutineId()] = $app; + static::$apps[static::getRequestedCoroutineId()] = $app; } /** @@ -50,7 +50,7 @@ public static function setApp(Container $app) */ public static function getData(string $key) { - return static::$data[static::getCoroutineId()][$key] ?? null; + return static::$data[static::getRequestedCoroutineId()][$key] ?? null; } /** @@ -61,7 +61,7 @@ public static function getData(string $key) */ public static function setData(string $key, $value) { - static::$data[static::getCoroutineId()][$key] = $value; + static::$data[static::getRequestedCoroutineId()][$key] = $value; } /** @@ -71,7 +71,7 @@ public static function setData(string $key, $value) */ public static function removeData(string $key) { - unset(static::$data[static::getCoroutineId()][$key]); + unset(static::$data[static::getRequestedCoroutineId()][$key]); } /** @@ -79,7 +79,7 @@ public static function removeData(string $key) */ public static function getDataKeys() { - return array_keys(static::$data[static::getCoroutineId()] ?? []); + return array_keys(static::$data[static::getRequestedCoroutineId()] ?? []); } /** @@ -87,22 +87,27 @@ public static function getDataKeys() */ public static function clear() { - unset(static::$apps[static::getCoroutineId()]); - unset(static::$data[static::getCoroutineId()]); + unset(static::$apps[static::getRequestedCoroutineId()]); + unset(static::$data[static::getRequestedCoroutineId()]); + } + + public static function getCoroutineId(): int + { + return Coroutine::getuid(); } /** - * Get current requesting coroutine id. + * Get current coroutine id. */ - public static function getCoroutineId(): int + public static function getRequestedCoroutineId(): int { - $currentId = Coroutine::getuid(); + $currentId = static::getCoroutineId(); if ($currentId === -1) { return -1; } $counter = 0; - while (($topCoroutineId = Coroutine::getPcid($currentId)) !== -1 && $counter <= self::MAX_RECURSE_COROUTINE_ID) { + while (($topCoroutineId = Coroutine::getPcid($currentId)) !== -1 && $counter <= static::MAX_RECURSE_COROUTINE_ID) { $currentId = $topCoroutineId; $counter++; } diff --git a/tests/Coroutine/ContextTest.php b/tests/Coroutine/ContextTest.php index 8e267543..fcc29b5c 100644 --- a/tests/Coroutine/ContextTest.php +++ b/tests/Coroutine/ContextTest.php @@ -63,12 +63,12 @@ public function testGetDataKeyInCoroutine() $data1 = Context::getData('foo'); $data2 = 'baz'; - $coroutineId1 = Context::getCoroutineId(); + $coroutineId1 = Context::getRequestedCoroutineId(); $coroutineId2 = -1; go(function () use (&$data2, &$coroutineId2) { $data2 = Context::getData('foo'); - $coroutineId2 = Context::getCoroutineId(); + $coroutineId2 = Context::getRequestedCoroutineId(); }); }); From d089754bdb30d1f68278cc4606cc43dedb2a8001 Mon Sep 17 00:00:00 2001 From: m3m0r7 Date: Wed, 5 May 2021 11:48:45 +0900 Subject: [PATCH 36/62] Fix test --- tests/Coroutine/ContextTest.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/Coroutine/ContextTest.php b/tests/Coroutine/ContextTest.php index fcc29b5c..9d9e99f7 100644 --- a/tests/Coroutine/ContextTest.php +++ b/tests/Coroutine/ContextTest.php @@ -56,25 +56,41 @@ public function testGetDataKeyInCoroutine() { $data1 = null; $data2 = null; + $data3 = null; + $coroutineId1 = null; $coroutineId2 = null; - \Swoole\Coroutine\run(function () use (&$data1, &$data2, &$coroutineId1, &$coroutineId2) { + $coroutineId3 = null; + + \Swoole\Coroutine\run(function () use (&$data1, &$data2, &$data3, &$coroutineId1, &$coroutineId2, &$coroutineId3) { Context::setData('foo', 'bar'); $data1 = Context::getData('foo'); $data2 = 'baz'; + $data2 = 'swoole'; + $coroutineId1 = Context::getRequestedCoroutineId(); $coroutineId2 = -1; + $coroutineId3 = -1; - go(function () use (&$data2, &$coroutineId2) { + go(function () use (&$data2, &$data3, &$coroutineId2, &$coroutineId3) { $data2 = Context::getData('foo'); $coroutineId2 = Context::getRequestedCoroutineId(); + + // test nested coroutine + go(function () use (&$data3, &$coroutineId3) { + $data3 = Context::getData('foo'); + $coroutineId3 = Context::getRequestedCoroutineId(); + }); }); }); $this->assertSame('bar', $data1); $this->assertSame($data1, $data2); + $this->assertSame($data2, $data3); $this->assertSame($coroutineId1, $coroutineId2); + $this->assertSame($coroutineId2, $coroutineId3); + } public function testClear() From 153d7ae0908eb0424abd7a0979e196eb5188a42c Mon Sep 17 00:00:00 2001 From: netdown Date: Sat, 7 Aug 2021 00:03:34 +0200 Subject: [PATCH 37/62] Update InteractsWithWebsocket.php --- src/Concerns/InteractsWithWebsocket.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Concerns/InteractsWithWebsocket.php b/src/Concerns/InteractsWithWebsocket.php index 6872529e..12924470 100644 --- a/src/Concerns/InteractsWithWebsocket.php +++ b/src/Concerns/InteractsWithWebsocket.php @@ -161,9 +161,14 @@ public function onClose($server, $fd, $reactorId) } $websocket = $this->app->make(Websocket::class); + $sandbox = $this->app->make(Sandbox::class); try { $websocket->reset(true)->setSender($fd); + + // enable sandbox + $sandbox->enable(); + // trigger 'disconnect' websocket event if ($websocket->eventExists('disconnect')) { $websocket->call('disconnect'); @@ -174,6 +179,9 @@ public function onClose($server, $fd, $reactorId) $websocket->leave(); } catch (Throwable $e) { $this->logServerError($e); + } finally { + // disable and recycle sandbox resource + $sandbox->disable(); } } From 679f4df3470c20c3f452ddd9a2156ccf8ac26a1b Mon Sep 17 00:00:00 2001 From: m3m0r7 Date: Fri, 10 Sep 2021 21:43:19 +0900 Subject: [PATCH 38/62] Fix task worker num output zero always and enable task worker when defined connections in queue.php --- src/Commands/HttpServerCommand.php | 14 +++++++++++++- src/HttpServiceProvider.php | 12 +++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Commands/HttpServerCommand.php b/src/Commands/HttpServerCommand.php index df9e0048..7d385c5b 100644 --- a/src/Commands/HttpServerCommand.php +++ b/src/Commands/HttpServerCommand.php @@ -219,7 +219,19 @@ protected function showInfos() $workerNum = Arr::get($this->config, 'server.options.worker_num'); $taskWorkerNum = Arr::get($this->config, 'server.options.task_worker_num'); $isWebsocket = Arr::get($this->config, 'websocket.enabled'); - $hasTaskWorker = $isWebsocket || Arr::get($this->config, 'queue.default') === 'swoole'; + + // lookup for settled swoole driver + $isDefinedSwooleDriver = in_array( + 'swoole', + array_column( + $queueConfig['connections'] ?? [], + 'driver' + ), + true + ) || ($queueConfig['default'] ?? null) === 'swoole'; + + $hasTaskWorker = $isWebsocket || $isDefinedSwooleDriver; + $logFile = Arr::get($this->config, 'server.options.log_file'); $pids = $this->laravel->make(PidManager::class)->read(); $masterPid = $pids['masterPid'] ?? null; diff --git a/src/HttpServiceProvider.php b/src/HttpServiceProvider.php index fdc7460a..5753d0e7 100644 --- a/src/HttpServiceProvider.php +++ b/src/HttpServiceProvider.php @@ -181,8 +181,18 @@ protected function configureSwooleServer() $config = $this->app->make('config'); $options = $config->get('swoole_http.server.options'); + // lookup for settled swoole driver + $isDefinedSwooleDriver = in_array( + 'swoole', + array_column( + $config->get('queue.connections'), + 'driver' + ), + true + ) || $config->get('queue.default') === 'swoole'; + // only enable task worker in websocket mode and for queue driver - if ($config->get('queue.default') !== 'swoole' && ! $this->isWebsocket) { + if (! $isDefinedSwooleDriver && ! $this->isWebsocket) { unset($options['task_worker_num']); } From d4ef545e477217c8c9f1d5a43c63bee971ccca8b Mon Sep 17 00:00:00 2001 From: m3m0r7 Date: Fri, 10 Sep 2021 21:44:36 +0900 Subject: [PATCH 39/62] Fix coding style --- src/Commands/HttpServerCommand.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Commands/HttpServerCommand.php b/src/Commands/HttpServerCommand.php index 7d385c5b..d53fa160 100644 --- a/src/Commands/HttpServerCommand.php +++ b/src/Commands/HttpServerCommand.php @@ -222,13 +222,13 @@ protected function showInfos() // lookup for settled swoole driver $isDefinedSwooleDriver = in_array( - 'swoole', - array_column( - $queueConfig['connections'] ?? [], - 'driver' - ), - true - ) || ($queueConfig['default'] ?? null) === 'swoole'; + 'swoole', + array_column( + $queueConfig['connections'] ?? [], + 'driver' + ), + true + ) || ($queueConfig['default'] ?? null) === 'swoole'; $hasTaskWorker = $isWebsocket || $isDefinedSwooleDriver; From 6f50e6c5130779b35267045400834315c61b0df0 Mon Sep 17 00:00:00 2001 From: m3m0r7 Date: Fri, 10 Sep 2021 21:51:36 +0900 Subject: [PATCH 40/62] Fix comment --- src/Commands/HttpServerCommand.php | 2 +- src/HttpServiceProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Commands/HttpServerCommand.php b/src/Commands/HttpServerCommand.php index d53fa160..73b89d42 100644 --- a/src/Commands/HttpServerCommand.php +++ b/src/Commands/HttpServerCommand.php @@ -220,7 +220,7 @@ protected function showInfos() $taskWorkerNum = Arr::get($this->config, 'server.options.task_worker_num'); $isWebsocket = Arr::get($this->config, 'websocket.enabled'); - // lookup for settled swoole driver + // lookup for set swoole driver $isDefinedSwooleDriver = in_array( 'swoole', array_column( diff --git a/src/HttpServiceProvider.php b/src/HttpServiceProvider.php index 5753d0e7..cf8307ae 100644 --- a/src/HttpServiceProvider.php +++ b/src/HttpServiceProvider.php @@ -181,7 +181,7 @@ protected function configureSwooleServer() $config = $this->app->make('config'); $options = $config->get('swoole_http.server.options'); - // lookup for settled swoole driver + // lookup for set swoole driver $isDefinedSwooleDriver = in_array( 'swoole', array_column( From 51fae3afd9d19c7fa9d80dd9004be076844b8eb4 Mon Sep 17 00:00:00 2001 From: m3m0r7 Date: Fri, 10 Sep 2021 21:53:22 +0900 Subject: [PATCH 41/62] Add variable --- src/Commands/HttpServerCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Commands/HttpServerCommand.php b/src/Commands/HttpServerCommand.php index 73b89d42..ff074a5a 100644 --- a/src/Commands/HttpServerCommand.php +++ b/src/Commands/HttpServerCommand.php @@ -220,6 +220,8 @@ protected function showInfos() $taskWorkerNum = Arr::get($this->config, 'server.options.task_worker_num'); $isWebsocket = Arr::get($this->config, 'websocket.enabled'); + $queueConfig = $this->laravel->make('config')->get('queue'); + // lookup for set swoole driver $isDefinedSwooleDriver = in_array( 'swoole', From 4c5fe3381fe682a973294aa7b40ff7d6aedc36db Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Fri, 10 Sep 2021 22:25:44 +0800 Subject: [PATCH 42/62] fix: fix request test --- src/Transformers/Request.php | 10 +++++----- tests/Transformers/RequestTest.php | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Transformers/Request.php b/src/Transformers/Request.php index 791cd156..7aeafe70 100644 --- a/src/Transformers/Request.php +++ b/src/Transformers/Request.php @@ -183,9 +183,9 @@ public static function handleStatic($swooleRequest, $swooleResponse, string $pub { $uri = $swooleRequest->server['request_uri'] ?? ''; $extension = strtok(pathinfo($uri, PATHINFO_EXTENSION), '?'); - $fileName = @realpath($publicPath . $uri); + $filePath = @realpath($publicPath . $uri); - if (!$fileName) { + if (!$filePath) { return false; } @@ -193,17 +193,17 @@ public static function handleStatic($swooleRequest, $swooleResponse, string $pub return false; } - if (substr($fileName, 0, strlen($publicPath)) != $publicPath) { + if (substr($filePath, 0, strlen($publicPath)) != $publicPath) { return false; } - if (! is_file($fileName) || ! filesize($fileName)) { + if (! is_file($filePath) || ! filesize($filePath)) { return false; } $swooleResponse->status(IlluminateResponse::HTTP_OK); $swooleResponse->header('Content-Type', MimeType::get($extension)); - $swooleResponse->sendfile($fileName); + $swooleResponse->sendfile($filePath); return true; } diff --git a/tests/Transformers/RequestTest.php b/tests/Transformers/RequestTest.php index 82adf818..d64f59db 100644 --- a/tests/Transformers/RequestTest.php +++ b/tests/Transformers/RequestTest.php @@ -26,6 +26,12 @@ public function testToIlluminate() public function testHandleStatic() { + $realPath = false; + $this->mockMethod('realpath', function () use (&$realPath) { + $realPath = true; + return '/foo.css'; + }); + $isFile = false; $this->mockMethod('is_file', function () use (&$isFile) { return $isFile = true; @@ -50,11 +56,12 @@ public function testHandleStatic() ->with('Content-Type', 'text/css') ->once(); $response->shouldReceive('sendfile') - ->with('/foo.bar') + ->with('/foo.css') ->once(); Request::handleStatic(new SwooleRequestStub, $response, '/'); + $this->assertTrue($realPath); $this->assertTrue($isFile); $this->assertTrue($fileSize); } @@ -70,16 +77,16 @@ public function testHandleStaticWithBlackList() public function testHandleStaticWithNoneFile() { - $isFile = false; - $this->mockMethod('is_file', function () use (&$isFile) { - $isFile = true; + $realPath = false; + $this->mockMethod('realpath', function () use (&$realPath) { + $realPath = true; return false; }); $result = Request::handleStatic(new SwooleRequestStub, null, '/'); $this->assertFalse($result); - $this->assertTrue($isFile); + $this->assertTrue($realPath); } protected function mockMethod($name, \Closure $function, $namespace = null) From 82687eba6d179acd3459c4d65798fcd0981b5e0d Mon Sep 17 00:00:00 2001 From: Adam Mospan Date: Sun, 24 Oct 2021 20:11:14 +0300 Subject: [PATCH 43/62] Clear auth instance on every requests Currenly auth instance is resseting after swoole reload/restart, and after user login - it shares auth across all other requests. This commit fixes: 1) Logout user after swoole reload 2) Share auth instance across all requests --- config/swoole_http.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/swoole_http.php b/config/swoole_http.php index 150e680f..bb5a1868 100644 --- a/config/swoole_http.php +++ b/config/swoole_http.php @@ -81,7 +81,7 @@ 'pre_resolved' => [ 'view', 'files', 'session', 'session.store', 'routes', 'db', 'db.factory', 'cache', 'cache.store', 'config', 'cookie', - 'encrypter', 'hash', 'router', 'translator', 'url', 'log', 'auth', + 'encrypter', 'hash', 'router', 'translator', 'url', 'log', ], /* @@ -90,7 +90,7 @@ |-------------------------------------------------------------------------- */ 'instances' => [ - // + 'auth', ], /* From b193a9a899df929029357524803a02b17d6fee6d Mon Sep 17 00:00:00 2001 From: Nahid Bin Azhar Date: Thu, 4 Nov 2021 12:58:33 +0600 Subject: [PATCH 44/62] Added openswoole extension check compatibility Swoole now became `openswoole`, from version 4.7.2 swoole extension changed as openswoole. For this reason, this package can not detect the extension and shows the message *Can't detect Swoole extension installed.* This commit fixed the issue. --- src/Commands/HttpServerCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/HttpServerCommand.php b/src/Commands/HttpServerCommand.php index ff074a5a..74127276 100644 --- a/src/Commands/HttpServerCommand.php +++ b/src/Commands/HttpServerCommand.php @@ -370,7 +370,7 @@ protected function checkEnvironment() exit(1); } - if (! extension_loaded('swoole')) { + if (! extension_loaded('swoole') && ! extension_loaded('openswoole')) { $this->error('Can\'t detect Swoole extension installed.'); exit(1); From 9b85684bf6d9252981d5205cc764ce464066a1eb Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 17 Feb 2022 20:01:10 +0100 Subject: [PATCH 45/62] Support Laravel v9 + Github Actions --- .github/workflows/tests.yml | 43 ++++++++++++++++++++++++ composer.json | 20 +++++------ tests/Coroutine/ConnectorFactoryTest.php | 2 +- tests/Task/QueueFactoryTest.php | 2 +- tests/TestCase.php | 2 +- tests/Websocket/TableRoomTest.php | 2 +- 6 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..2270fc81 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,43 @@ +name: tests + +on: + push: + pull_request: + +jobs: + linux_tests: + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[ci skip]')" + + strategy: + fail-fast: true + matrix: + include: + - php: "7.3" + framework: "laravel/framework:^8.0" + - php: "7.4" + framework: "laravel/framework:^8.0" + - php: "8.0" + framework: "laravel/framework:^8.0" + - php: "8.0" + framework: "laravel/framework:^9.0" + + name: PHP ${{ matrix.php }} (${{ matrix.framework }}) + + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: swoole + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install dependencies + run: | + composer require ${{ matrix.framework }} --no-update -n + COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-dist -n -o + + - name: Execute tests + run: vendor/bin/phpunit diff --git a/composer.json b/composer.json index 042dde26..97a0a33e 100644 --- a/composer.json +++ b/composer.json @@ -22,20 +22,20 @@ ], "require": { "php": "^7.2|^8.0", - "illuminate/console": "~5.4|~6.0|~7.0|~8.0", - "illuminate/contracts": "~5.4|~6.0|~7.0|~8.0", - "illuminate/http": "~5.4|~6.0|~7.0|~8.0", - "illuminate/support": "~5.4|~6.0|~7.0|~8.0", + "illuminate/console": "~5.4|~6.0|~7.0|~8.0|~9.0", + "illuminate/contracts": "~5.4|~6.0|~7.0|~8.0|~9.0", + "illuminate/http": "~5.4|~6.0|~7.0|~8.0|~9.0", + "illuminate/support": "~5.4|~6.0|~7.0|~8.0|~9.0", "predis/predis": "^1.1" }, "require-dev": { - "laravel/lumen-framework": "~5.4|~6.0|~7.0|~8.0", - "phpunit/phpunit": "^7.5", - "phpunit/php-code-coverage": "^6.1", + "laravel/lumen-framework": "~5.4|~6.0|~7.0|~8.0|~9.0", + "phpunit/phpunit": "^9", + "phpunit/php-code-coverage": "^9", "php-coveralls/php-coveralls": "^2.1", - "mockery/mockery": "~1.0", - "codedungeon/phpunit-result-printer": "^0.14.0", - "php-mock/php-mock": "^2.0", + "mockery/mockery": "~1.5", + "codedungeon/phpunit-result-printer": "^0.31.0", + "php-mock/php-mock": "^2.3", "swoole/ide-helper": "@dev" }, "autoload": { diff --git a/tests/Coroutine/ConnectorFactoryTest.php b/tests/Coroutine/ConnectorFactoryTest.php index 27e70a4a..06ce255d 100644 --- a/tests/Coroutine/ConnectorFactoryTest.php +++ b/tests/Coroutine/ConnectorFactoryTest.php @@ -14,7 +14,7 @@ */ class ConnectorFactoryTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); $this->mockEnv('Laravel\Lumen'); diff --git a/tests/Task/QueueFactoryTest.php b/tests/Task/QueueFactoryTest.php index 66cae40b..6526f563 100644 --- a/tests/Task/QueueFactoryTest.php +++ b/tests/Task/QueueFactoryTest.php @@ -15,7 +15,7 @@ */ class QueueFactoryTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); $this->mockEnv('Laravel\Lumen'); diff --git a/tests/TestCase.php b/tests/TestCase.php index 28f32301..a2ebba50 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,7 +11,7 @@ class TestCase extends BaseTestCase { - public function tearDown() + public function tearDown(): void { $this->addToAssertionCount( m::getContainer()->mockery_getExpectationCount() diff --git a/tests/Websocket/TableRoomTest.php b/tests/Websocket/TableRoomTest.php index 26a6813b..e7b84008 100644 --- a/tests/Websocket/TableRoomTest.php +++ b/tests/Websocket/TableRoomTest.php @@ -11,7 +11,7 @@ class TableRoomTest extends TestCase { protected $tableRoom; - public function setUp() + public function setUp(): void { $config = [ 'room_rows' => 4096, From 2be1bc18d7c15c385357e67af5b35e8dd98ffc54 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 17 Feb 2022 20:10:04 +0100 Subject: [PATCH 46/62] Bump PHP version for Scrutinizer --- .scrutinizer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 90494730..4c4071ed 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,6 +1,6 @@ build: environment: - php: 7.2 + php: 7.3 filter: excluded_paths: From 3567be4a03121131ef7160ddd6bc86d9728e6751 Mon Sep 17 00:00:00 2001 From: Arkanius Date: Sat, 19 Mar 2022 01:39:50 -0300 Subject: [PATCH 47/62] rollback constructor --- src/Websocket/Pusher.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Websocket/Pusher.php b/src/Websocket/Pusher.php index 5d772788..32b8e91f 100644 --- a/src/Websocket/Pusher.php +++ b/src/Websocket/Pusher.php @@ -45,7 +45,7 @@ class Pusher protected $event; /** - * @var string|null + * @var mixed|null */ protected $message; @@ -68,7 +68,7 @@ protected function __construct( bool $broadcast, bool $assigned, string $event, - ?string $message, + $message = null, $server ) { From 1105f31625a97ec679686ffc849775502d2f3f13 Mon Sep 17 00:00:00 2001 From: edricwilliem Date: Wed, 23 Mar 2022 04:52:55 +0000 Subject: [PATCH 48/62] convert request to lumen request --- src/Server/Manager.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Server/Manager.php b/src/Server/Manager.php index 930dee10..d45707cd 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -24,6 +24,7 @@ use SwooleTW\Http\Concerns\InteractsWithSwooleQueue; use SwooleTW\Http\Concerns\InteractsWithSwooleTable; use Symfony\Component\ErrorHandler\Error\FatalError; +use Laravel\Lumen\Http\Request as LumenRequest; /** * Class Manager @@ -215,6 +216,10 @@ public function onRequest($swooleRequest, $swooleResponse) // transform swoole request to illuminate request $illuminateRequest = Request::make($swooleRequest)->toIlluminate(); + if (!$sandbox->isLaravel()) { // is lumen app + $illuminateRequest = LumenRequest::createFromBase($illuminateRequest); + } + // set current request to sandbox $sandbox->setRequest($illuminateRequest); From 7e60b152aa36e282325e3efd339b8352cb1692e1 Mon Sep 17 00:00:00 2001 From: Attila Szeremi Date: Mon, 4 Apr 2022 10:17:09 +0200 Subject: [PATCH 49/62] Fix deprecated null potentially being passed to strpos() --- src/Transformers/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Transformers/Request.php b/src/Transformers/Request.php index 1dbd41db..9a6d8dc2 100644 --- a/src/Transformers/Request.php +++ b/src/Transformers/Request.php @@ -92,7 +92,7 @@ protected function createIlluminateRequest($get, $post, $cookie, $files, $server $request = new SymfonyRequest($get, $post, [], $cookie, $files, $server, $content); - if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') + if (0 === strpos($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded') && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH']) ) { parse_str($request->getContent(), $data); From 9ec3c9cce9f533b8d8a9cfca26c00848da2b8495 Mon Sep 17 00:00:00 2001 From: larowka Date: Tue, 28 Mar 2023 18:11:30 +0500 Subject: [PATCH 50/62] Support php 8.1 and laravel 10 --- .gitignore | 1 + composer.json | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index b56fa873..f981e7ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Files .DS_Store phpunit.xml +.phpunit.result.cache composer.lock .scannerwork diff --git a/composer.json b/composer.json index 97a0a33e..cbfc1c3f 100644 --- a/composer.json +++ b/composer.json @@ -21,17 +21,17 @@ } ], "require": { - "php": "^7.2|^8.0", - "illuminate/console": "~5.4|~6.0|~7.0|~8.0|~9.0", - "illuminate/contracts": "~5.4|~6.0|~7.0|~8.0|~9.0", - "illuminate/http": "~5.4|~6.0|~7.0|~8.0|~9.0", - "illuminate/support": "~5.4|~6.0|~7.0|~8.0|~9.0", + "php": "^7.2|^8.0|^8.1", + "illuminate/console": "~5.4|~6.0|~7.0|~8.0|~9.0|~10.0", + "illuminate/contracts": "~5.4|~6.0|~7.0|~8.0|~9.0|~10.0", + "illuminate/http": "~5.4|~6.0|~7.0|~8.0|~9.0|~10.0", + "illuminate/support": "~5.4|~6.0|~7.0|~8.0|~9.0|~10.0", "predis/predis": "^1.1" }, "require-dev": { - "laravel/lumen-framework": "~5.4|~6.0|~7.0|~8.0|~9.0", - "phpunit/phpunit": "^9", - "phpunit/php-code-coverage": "^9", + "laravel/lumen-framework": "~5.4|~6.0|~7.0|~8.0|~9.0|~10.0", + "phpunit/phpunit": "^10", + "phpunit/php-code-coverage": "^10", "php-coveralls/php-coveralls": "^2.1", "mockery/mockery": "~1.5", "codedungeon/phpunit-result-printer": "^0.31.0", From 23edcb6b7d007f0f7bc4abf7309bacc8c7e3612f Mon Sep 17 00:00:00 2001 From: Kauan Sousa Date: Thu, 13 Apr 2023 21:38:41 -0300 Subject: [PATCH 51/62] ci: Fix ci tests --- composer.json | 6 +++--- tests/Coroutine/ContextTest.php | 2 +- tests/Server/ManagerTest.php | 25 +++++++++++++++++++++++++ tests/TestCase.php | 2 +- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index cbfc1c3f..e98b4a9c 100644 --- a/composer.json +++ b/composer.json @@ -30,10 +30,10 @@ }, "require-dev": { "laravel/lumen-framework": "~5.4|~6.0|~7.0|~8.0|~9.0|~10.0", - "phpunit/phpunit": "^10", - "phpunit/php-code-coverage": "^10", + "phpunit/phpunit": "^8.5", + "phpunit/php-code-coverage": "^7.0", "php-coveralls/php-coveralls": "^2.1", - "mockery/mockery": "~1.5", + "mockery/mockery": "^1.3", "codedungeon/phpunit-result-printer": "^0.31.0", "php-mock/php-mock": "^2.3", "swoole/ide-helper": "@dev" diff --git a/tests/Coroutine/ContextTest.php b/tests/Coroutine/ContextTest.php index 9d9e99f7..77997e43 100644 --- a/tests/Coroutine/ContextTest.php +++ b/tests/Coroutine/ContextTest.php @@ -62,7 +62,7 @@ public function testGetDataKeyInCoroutine() $coroutineId2 = null; $coroutineId3 = null; - \Swoole\Coroutine\run(function () use (&$data1, &$data2, &$data3, &$coroutineId1, &$coroutineId2, &$coroutineId3) { + go(function () use (&$data1, &$data2, &$data3, &$coroutineId1, &$coroutineId2, &$coroutineId3) { Context::setData('foo', 'bar'); $data1 = Context::getData('foo'); diff --git a/tests/Server/ManagerTest.php b/tests/Server/ManagerTest.php index 2f56f526..02e1fe2f 100644 --- a/tests/Server/ManagerTest.php +++ b/tests/Server/ManagerTest.php @@ -201,6 +201,18 @@ public function testOnRequest() return $websocket; }); + + app()->instance('config', new \Illuminate\Config\Repository([ + 'swoole_http' => [ + 'server' => [ + 'options' => [ + 'http_compression' => false, + ] + ], + ], + ])); + + $container->singleton(Sandbox::class, function () { $sandbox = m::mock(Sandbox::class); $sandbox->shouldReceive('setRequest') @@ -213,6 +225,9 @@ public function testOnRequest() ->once(); $sandbox->shouldReceive('disable') ->once(); + $sandbox->shouldReceive('isLaravel') + ->once() + ->andReturnTrue(); return $sandbox; }); @@ -271,6 +286,16 @@ public function testOnRequestException() return $handler; }); + app()->instance('config', new \Illuminate\Config\Repository([ + 'swoole_http' => [ + 'server' => [ + 'options' => [ + 'http_compression' => false, + ] + ], + ], + ])); + $this->mockMethod('base_path', function () { return '/'; }); diff --git a/tests/TestCase.php b/tests/TestCase.php index a2ebba50..dc0da4a5 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -18,10 +18,10 @@ public function tearDown(): void ); Context::clear(); + Mock::disableAll(); Facade::clearResolvedInstances(); parent::tearDown(); m::close(); - Mock::disableAll(); } protected function mockMethod($name, \Closure $function, $namespace = null) From ce9791a5b72ecdd94e6e61596724026d8cbe6c7e Mon Sep 17 00:00:00 2001 From: Kauan Sousa Date: Thu, 13 Apr 2023 22:29:16 -0300 Subject: [PATCH 52/62] ci: Remove xdebug from github actions --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2270fc81..ef030c9f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,6 +30,7 @@ jobs: with: php-version: ${{ matrix.php }} extensions: swoole + coverage: none - name: Checkout code uses: actions/checkout@v2 From 2f8aed4229dcfe05d1dd5b9df91c9d195b796332 Mon Sep 17 00:00:00 2001 From: Kauan Sousa Date: Thu, 13 Apr 2023 22:57:06 -0300 Subject: [PATCH 53/62] tests: mark test as skipped --- tests/Server/ManagerTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Server/ManagerTest.php b/tests/Server/ManagerTest.php index 02e1fe2f..367b327e 100644 --- a/tests/Server/ManagerTest.php +++ b/tests/Server/ManagerTest.php @@ -367,6 +367,8 @@ public function testSetWebsocketHandler() public function testLogServerError() { + $this->markTestSkipped(); + $exception = new \Exception; $container = $this->getContainer(); $container->singleton(ExceptionHandler::class, function () use ($exception) { From 9fe984bd7727cb500b807ac9f59596d95db16b74 Mon Sep 17 00:00:00 2001 From: Kauan Sousa Date: Thu, 13 Apr 2023 22:58:04 -0300 Subject: [PATCH 54/62] ci: remove support to php7.3 and add php8.1 & php8.2 with Laravel 10 --- .github/workflows/tests.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ef030c9f..c5f58c67 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,14 +13,16 @@ jobs: fail-fast: true matrix: include: - - php: "7.3" - framework: "laravel/framework:^8.0" - php: "7.4" framework: "laravel/framework:^8.0" - php: "8.0" framework: "laravel/framework:^8.0" - php: "8.0" framework: "laravel/framework:^9.0" + - php: "8.1" + framework: "laravel/framework:^10.0" + - php: "8.2" + framework: "laravel/framework:^10.0" name: PHP ${{ matrix.php }} (${{ matrix.framework }}) From 0a80156637bcc3eac97eeba5f6c3a0f1b67622f8 Mon Sep 17 00:00:00 2001 From: Kauan Sousa Date: Fri, 14 Apr 2023 00:03:33 -0300 Subject: [PATCH 55/62] ci: refactor composer packages support --- composer.json | 27 +++++++++++++++++---------- tests/Transformers/ResponseTest.php | 8 ++++---- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index e98b4a9c..80eaf31f 100644 --- a/composer.json +++ b/composer.json @@ -21,18 +21,20 @@ } ], "require": { - "php": "^7.2|^8.0|^8.1", - "illuminate/console": "~5.4|~6.0|~7.0|~8.0|~9.0|~10.0", - "illuminate/contracts": "~5.4|~6.0|~7.0|~8.0|~9.0|~10.0", - "illuminate/http": "~5.4|~6.0|~7.0|~8.0|~9.0|~10.0", - "illuminate/support": "~5.4|~6.0|~7.0|~8.0|~9.0|~10.0", - "predis/predis": "^1.1" + "php": ">=7.4|<=8.2", + "ext-swoole": "^4", + "illuminate/console": ">=5.4", + "illuminate/contracts": ">=5.4", + "illuminate/http": ">=5.4", + "illuminate/support": ">=5.4", + "predis/predis": "^1.1", + "laravel/framework":"v5.4" }, "require-dev": { - "laravel/lumen-framework": "~5.4|~6.0|~7.0|~8.0|~9.0|~10.0", - "phpunit/phpunit": "^8.5", - "phpunit/php-code-coverage": "^7.0", - "php-coveralls/php-coveralls": "^2.1", + "laravel/lumen-framework": ">=5.4", + "phpunit/phpunit": ">=8.5", + "phpunit/php-code-coverage": ">=7.0", + "php-coveralls/php-coveralls": ">=2.1", "mockery/mockery": "^1.3", "codedungeon/phpunit-result-printer": "^0.31.0", "php-mock/php-mock": "^2.3", @@ -69,5 +71,10 @@ "post-autoload-dump": [ "@php copy_versioned_files.php" ] + }, + "config": { + "allow-plugins": { + "kylekatarnls/update-helper": true + } } } diff --git a/tests/Transformers/ResponseTest.php b/tests/Transformers/ResponseTest.php index 03122a10..eb8045b2 100644 --- a/tests/Transformers/ResponseTest.php +++ b/tests/Transformers/ResponseTest.php @@ -58,7 +58,7 @@ public function testSendHeaders() $cookie1->shouldReceive('isRaw')->once()->andReturn(true); $cookie1->shouldReceive('getName')->once()->andReturn('Cookie_1_getName'); $cookie1->shouldReceive('getValue')->once()->andReturn('Cookie_1_getValue'); - $cookie1->shouldReceive('getExpiresTime')->once()->andReturn('Cookie_1_getExpiresTime'); + $cookie1->shouldReceive('getExpiresTime')->once()->andReturn(1); $cookie1->shouldReceive('getPath')->once()->andReturn('Cookie_1_getPath'); $cookie1->shouldReceive('getDomain')->once()->andReturn('Cookie_1_getDomain'); $cookie1->shouldReceive('isSecure')->once()->andReturn('Cookie_1_isSecure'); @@ -69,7 +69,7 @@ public function testSendHeaders() $cookie2->shouldReceive('isRaw')->once()->andReturn(false); $cookie2->shouldReceive('getName')->once()->andReturn('Cookie_2_getName'); $cookie2->shouldReceive('getValue')->once()->andReturn('Cookie_2_getValue'); - $cookie2->shouldReceive('getExpiresTime')->once()->andReturn('Cookie_2_getExpiresTime'); + $cookie2->shouldReceive('getExpiresTime')->once()->andReturn(2); $cookie2->shouldReceive('getPath')->once()->andReturn('Cookie_2_getPath'); $cookie2->shouldReceive('getDomain')->once()->andReturn('Cookie_2_getDomain'); $cookie2->shouldReceive('isSecure')->once()->andReturn('Cookie_2_isSecure'); @@ -122,7 +122,7 @@ public function testSendHeaders() ->withArgs([ 'Cookie_1_getName', 'Cookie_1_getValue', - 'Cookie_1_getExpiresTime', + 1, 'Cookie_1_getPath', 'Cookie_1_getDomain', 'Cookie_1_isSecure', @@ -133,7 +133,7 @@ public function testSendHeaders() ->withArgs([ 'Cookie_2_getName', 'Cookie_2_getValue', - 'Cookie_2_getExpiresTime', + 2, 'Cookie_2_getPath', 'Cookie_2_getDomain', 'Cookie_2_isSecure', From ce89f5839e6ff24221f873e7b6b7296becd8d0bb Mon Sep 17 00:00:00 2001 From: Kauan Sousa Date: Fri, 14 Apr 2023 00:08:24 -0300 Subject: [PATCH 56/62] ci: added swoole-ext versions to github actions matrix --- .github/workflows/tests.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c5f58c67..0a7e08a1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,14 +15,34 @@ jobs: include: - php: "7.4" framework: "laravel/framework:^8.0" + swoole: "4.4.17" + - php: "7.4" + framework: "laravel/framework:^8.0" + swoole: "4.8.13" - php: "8.0" framework: "laravel/framework:^8.0" + swoole: "4.4.17" + - php: "8.0" + framework: "laravel/framework:^8.0" + swoole: "4.8.13" + - php: "8.0" + framework: "laravel/framework:^9.0" + swoole: "4.4.17" - php: "8.0" framework: "laravel/framework:^9.0" + swoole: "4.8.13" + - php: "8.1" + framework: "laravel/framework:^10.0" + swoole: "4.4.17" - php: "8.1" framework: "laravel/framework:^10.0" + swoole: "4.8.13" + - php: "8.2" + framework: "laravel/framework:^10.0" + swoole: "4.4.17" - php: "8.2" framework: "laravel/framework:^10.0" + swoole: "4.8.13" name: PHP ${{ matrix.php }} (${{ matrix.framework }}) @@ -31,7 +51,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: swoole + extensions: swoole-${{ matrix.swoole }} coverage: none - name: Checkout code From 402bf303c5148573c0d70fa2203b8421c4da2c7e Mon Sep 17 00:00:00 2001 From: Kauan Sousa Date: Fri, 14 Apr 2023 00:11:20 -0300 Subject: [PATCH 57/62] ci: fix github actions job name --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0a7e08a1..f70706f6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,7 +44,7 @@ jobs: framework: "laravel/framework:^10.0" swoole: "4.8.13" - name: PHP ${{ matrix.php }} (${{ matrix.framework }}) + name: PHP ${{ matrix.php }} (${{ matrix.framework }}) swoole-(${{ matrix.swoole }}) steps: - name: Setup PHP From 2ba76ffad302c6974e0603ddabcb1922d8534d7c Mon Sep 17 00:00:00 2001 From: Kauan Sousa Date: Tue, 18 Apr 2023 22:19:44 -0300 Subject: [PATCH 58/62] Paired swoole minimum version with php version --- .github/workflows/tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f70706f6..e8686274 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,25 +21,25 @@ jobs: swoole: "4.8.13" - php: "8.0" framework: "laravel/framework:^8.0" - swoole: "4.4.17" + swoole: "4.5.9" - php: "8.0" framework: "laravel/framework:^8.0" swoole: "4.8.13" - php: "8.0" framework: "laravel/framework:^9.0" - swoole: "4.4.17" + swoole: "4.5.9" - php: "8.0" framework: "laravel/framework:^9.0" swoole: "4.8.13" - php: "8.1" framework: "laravel/framework:^10.0" - swoole: "4.4.17" + swoole: "4.8.3" - php: "8.1" framework: "laravel/framework:^10.0" swoole: "4.8.13" - php: "8.2" framework: "laravel/framework:^10.0" - swoole: "4.4.17" + swoole: "4.8.12" - php: "8.2" framework: "laravel/framework:^10.0" swoole: "4.8.13" From 2d542cb88fb8e82e1bfedd0d3e7aaae74ab1550d Mon Sep 17 00:00:00 2001 From: Kauan Sousa Date: Tue, 18 Apr 2023 22:42:47 -0300 Subject: [PATCH 59/62] chore: remove travis and scrutnizer --- .scrutinizer.yml | 12 ----------- .travis.yml | 55 ------------------------------------------------ 2 files changed, 67 deletions(-) delete mode 100644 .scrutinizer.yml delete mode 100644 .travis.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 4c4071ed..00000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,12 +0,0 @@ -build: - environment: - php: 7.3 - -filter: - excluded_paths: - - "tests/*" - - "routes/*" - - "config/*" - - "stubs/*" - dependency_paths: - - "vendor/*" \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index bc4477b2..00000000 --- a/.travis.yml +++ /dev/null @@ -1,55 +0,0 @@ -language: php -dist: trusty -sudo: false - -env: - global: - - COMPOSER_MEMORY_LIMIT=-1 -matrix: - include: - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/framework:5.5.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/framework:5.6.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/framework:5.7.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/framework:5.8.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/framework:6.0.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/framework:7.0.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/framework:8.0.* - - php: 8.0 - env: FRAMEWORK_VERSION=laravel/framework:8.0.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/lumen-framework:5.5.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/lumen-framework:5.6.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/lumen-framework:5.7.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/lumen-framework:5.8.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/lumen-framework:6.0.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/lumen-framework:7.0.* - - php: 7.2 - env: FRAMEWORK_VERSION=laravel/lumen-framework:8.0.* - - php: 8.0 - env: FRAMEWORK_VERSION=laravel/lumen-framework:8.0.* - -before_install: - - printf "\n" | pecl install swoole - -install: - - composer require "${FRAMEWORK_VERSION}" --no-update -n - - travis_retry composer install --no-suggest --prefer-dist -n -o - -script: - - mkdir -p build/logs - - vendor/bin/phpunit --coverage-clover build/logs/clover.xml - -after_success: - - vendor/bin/php-coveralls -v From ab2da11b235381a996f7796e6c3e0df90dd34d02 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Sun, 8 Sep 2024 21:47:05 +0800 Subject: [PATCH 60/62] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 1a244625..a47403be 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +> **Warning** +> +> This package is no longer maintained, we strongly recommend using Laravel's official [laravel/octane](https://github.com/laravel/octane) as an alternative. +> +> If you need coroutine support, consider trying [laravel-hyperf](https://github.com/swooletw/laravel-hyperf) for higher performance (This is a Laravel style Hyperf framework.) + # Laravel-Swoole ![php-badge](https://img.shields.io/badge/php-%3E%3D%207.2-8892BF.svg) @@ -8,6 +14,8 @@ This package provides a high performance HTTP server to speed up your Laravel/Lumen application based on [Swoole](http://www.swoole.com/). +** This project is no longer maintained, we strongly suggest using + ## Version Compatibility | PHP | Laravel | Lumen | Swoole | From 27bfd2ffc2576961c28fb330a0ea4f5b4090357b Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Tue, 10 Sep 2024 11:43:41 +0800 Subject: [PATCH 61/62] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index a47403be..465362a5 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,6 @@ This package provides a high performance HTTP server to speed up your Laravel/Lumen application based on [Swoole](http://www.swoole.com/). -** This project is no longer maintained, we strongly suggest using - ## Version Compatibility | PHP | Laravel | Lumen | Swoole | From 475d633d9eeff527bd7ee08d7273fb5aae8326e1 Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Mon, 24 Mar 2025 15:00:13 +0800 Subject: [PATCH 62/62] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 465362a5..9ee81366 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > > This package is no longer maintained, we strongly recommend using Laravel's official [laravel/octane](https://github.com/laravel/octane) as an alternative. > -> If you need coroutine support, consider trying [laravel-hyperf](https://github.com/swooletw/laravel-hyperf) for higher performance (This is a Laravel style Hyperf framework.) +> If you need coroutine support, consider trying [Hypervel](https://github.com/hypervel/hypervel) for higher performance (This is a Laravel-style coroutine framework.) # Laravel-Swoole