diff --git a/src/Server/Manager.php b/src/Server/Manager.php index b93e66c9..4258a707 100644 --- a/src/Server/Manager.php +++ b/src/Server/Manager.php @@ -5,6 +5,7 @@ use Exception; use Throwable; use Swoole\Process; +use Swoole\Server\Task; use Illuminate\Support\Str; use SwooleTW\Http\Helpers\OS; use SwooleTW\Http\Server\Sandbox; @@ -256,13 +257,13 @@ protected function resetOnRequest() * Set onTask listener. * * @param mixed $server - * @param string|\Swoole\Server\Task $taskIdOrTask - * @param string $srcWorkerId Optional - * @param mixed $data Optional + * @param string|\Swoole\Server\Task $taskId or $task + * @param string $srcWorkerId + * @param mixed $data */ - public function onTask($server, ...$args) + public function onTask($server, $taskId, $srcWorkerId, $data) { - $this->container->make('events')->dispatch('swoole.task', [$server, $args]); + $this->container->make('events')->dispatch('swoole.task', func_get_args()); try { // push websocket message diff --git a/src/Transformers/Response.php b/src/Transformers/Response.php index 6c7e053a..416a26fa 100644 --- a/src/Transformers/Response.php +++ b/src/Transformers/Response.php @@ -10,6 +10,8 @@ class Response { + const CHUNK_SIZE = 8192; + /** * @var \Swoole\Http\Response */ @@ -46,7 +48,7 @@ public function __construct($illuminateResponse, SwooleResponse $swooleResponse) } /** - * Sends HTTP headers and content. + * Send HTTP headers and content. * * @throws \InvalidArgumentException */ @@ -57,7 +59,7 @@ public function send() } /** - * Sends HTTP headers. + * Send HTTP headers. * * @throws \InvalidArgumentException */ @@ -86,9 +88,11 @@ protected function sendHeaders() $this->swooleResponse->status($illuminateResponse->getStatusCode()); // cookies + // $cookie->isRaw() is supported after symfony/http-foundation 3.1 + // and Laravel 5.3, so we can add it back now foreach ($illuminateResponse->headers->getCookies() as $cookie) { - // may need to consider rawcookie - $this->swooleResponse->cookie( + $method = $cookie->isRaw() ? 'rawcookie' : 'cookie'; + $this->swooleResponse->$method( $cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), @@ -101,7 +105,7 @@ protected function sendHeaders() } /** - * Sends HTTP content. + * Send HTTP content. */ protected function sendContent() { @@ -124,10 +128,13 @@ protected function sendContent() */ protected function sendInChunk($content) { - if ($content) { - foreach (str_split($content, 1024) as $v) { - $this->swooleResponse->write($v); - } + if (strlen($content) <= static::CHUNK_SIZE) { + $this->swooleResponse->end($content); + return; + } + + foreach (str_split($content, static::CHUNK_SIZE) as $chunk) { + $this->swooleResponse->write($chunk); } $this->swooleResponse->end();