Skip to content

Commit 2d6dabb

Browse files
committed
- 优化DB日志输出
- 优化IteratorResponse输出,支持Generator中获取到连接状态
1 parent 2dedb70 commit 2d6dabb

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/concerns/InteractsWithHttp.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace think\swoole\concerns;
44

5+
use Generator;
56
use Swoole\Coroutine;
67
use Swoole\Coroutine\Http\Server;
78
use Swoole\Http\Request;
@@ -255,9 +256,20 @@ protected function sendIterator(Response $res, IteratorResponse $response)
255256
$this->setHeader($res, $response->getHeader());
256257
$this->setStatus($res, $response->getCode());
257258

258-
foreach ($response as $content) {
259-
$res->write($content);
259+
$iterator = $response->getIterator();
260+
261+
if ($iterator instanceof Generator) {
262+
while ($iterator->valid()) {
263+
$content = $iterator->current();
264+
$connected = $res->write($content);
265+
$iterator->send($connected);
266+
}
267+
} else {
268+
foreach ($iterator as $content) {
269+
$res->write($content);
270+
}
260271
}
272+
261273
$res->end();
262274
}
263275

@@ -268,8 +280,8 @@ protected function sendFile(Response $res, \think\Request $request, FileResponse
268280
$code = $response->getCode();
269281
$file = $response->getFile();
270282

271-
$ifNoneMatch = $request->header('If-None-Match');
272-
$ifRange = $request->header('If-Range');
283+
$ifNoneMatch = $request->header('If-None-Match');
284+
$ifRange = $request->header('If-Range');
273285
$eTag = $response->getHeader('ETag');
274286
$lastModified = $response->getHeader('Last-Modified');
275287

src/concerns/WithApplication.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Closure;
66
use think\App;
7+
use think\Container;
8+
use think\Log;
79
use think\swoole\App as SwooleApp;
810
use think\swoole\Manager;
911
use think\swoole\pool\Cache;
@@ -34,7 +36,9 @@ protected function prepareApplication(string $envName)
3436
if ($this->getConfig('pool.db.enable', true)) {
3537
$this->app->bind('db', Db::class);
3638
$this->app->resolving(Db::class, function (Db $db) {
37-
$db->setLog($this->container->log);
39+
$db->setLog(function ($type, $log) {
40+
Container::getInstance()->make(Log::class)->log($type, $log);
41+
});
3842
});
3943
}
4044
if ($this->getConfig('pool.cache.enable', true)) {

src/ipc/driver/Redis.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ public function getType()
2424

2525
public function prepare(\Swoole\Process\Pool $pool)
2626
{
27-
$connector = new PhpRedisConnector();
28-
29-
$connection = $connector->connect($this->config);
30-
31-
if (count($keys = $connection->keys("{$this->getPrefix()}*"))) {
32-
$connection->del($keys);
33-
}
34-
35-
$connector->disconnect($connection);
3627
}
3728

3829
public function subscribe()

0 commit comments

Comments
 (0)