Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit c266951

Browse files
authored
Merge pull request #233 from swooletw/develop
Develop
2 parents 9184fea + 0a39cad commit c266951

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/Server/Manager.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exception;
66
use Throwable;
77
use Swoole\Process;
8+
use Swoole\Server\Task;
89
use Illuminate\Support\Str;
910
use SwooleTW\Http\Helpers\OS;
1011
use SwooleTW\Http\Server\Sandbox;
@@ -256,13 +257,13 @@ protected function resetOnRequest()
256257
* Set onTask listener.
257258
*
258259
* @param mixed $server
259-
* @param string|\Swoole\Server\Task $taskIdOrTask
260-
* @param string $srcWorkerId Optional
261-
* @param mixed $data Optional
260+
* @param string|\Swoole\Server\Task $taskId or $task
261+
* @param string $srcWorkerId
262+
* @param mixed $data
262263
*/
263-
public function onTask($server, ...$args)
264+
public function onTask($server, $taskId, $srcWorkerId, $data)
264265
{
265-
$this->container->make('events')->dispatch('swoole.task', [$server, $args]);
266+
$this->container->make('events')->dispatch('swoole.task', func_get_args());
266267

267268
try {
268269
// push websocket message

src/Transformers/Response.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
class Response
1212
{
13+
const CHUNK_SIZE = 8192;
14+
1315
/**
1416
* @var \Swoole\Http\Response
1517
*/
@@ -46,7 +48,7 @@ public function __construct($illuminateResponse, SwooleResponse $swooleResponse)
4648
}
4749

4850
/**
49-
* Sends HTTP headers and content.
51+
* Send HTTP headers and content.
5052
*
5153
* @throws \InvalidArgumentException
5254
*/
@@ -57,7 +59,7 @@ public function send()
5759
}
5860

5961
/**
60-
* Sends HTTP headers.
62+
* Send HTTP headers.
6163
*
6264
* @throws \InvalidArgumentException
6365
*/
@@ -86,9 +88,11 @@ protected function sendHeaders()
8688
$this->swooleResponse->status($illuminateResponse->getStatusCode());
8789

8890
// cookies
91+
// $cookie->isRaw() is supported after symfony/http-foundation 3.1
92+
// and Laravel 5.3, so we can add it back now
8993
foreach ($illuminateResponse->headers->getCookies() as $cookie) {
90-
// may need to consider rawcookie
91-
$this->swooleResponse->cookie(
94+
$method = $cookie->isRaw() ? 'rawcookie' : 'cookie';
95+
$this->swooleResponse->$method(
9296
$cookie->getName(),
9397
$cookie->getValue(),
9498
$cookie->getExpiresTime(),
@@ -101,7 +105,7 @@ protected function sendHeaders()
101105
}
102106

103107
/**
104-
* Sends HTTP content.
108+
* Send HTTP content.
105109
*/
106110
protected function sendContent()
107111
{
@@ -124,10 +128,13 @@ protected function sendContent()
124128
*/
125129
protected function sendInChunk($content)
126130
{
127-
if ($content) {
128-
foreach (str_split($content, 1024) as $v) {
129-
$this->swooleResponse->write($v);
130-
}
131+
if (strlen($content) <= static::CHUNK_SIZE) {
132+
$this->swooleResponse->end($content);
133+
return;
134+
}
135+
136+
foreach (str_split($content, static::CHUNK_SIZE) as $chunk) {
137+
$this->swooleResponse->write($chunk);
131138
}
132139

133140
$this->swooleResponse->end();

0 commit comments

Comments
 (0)