hhxsv5 / laravel-s

LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

有时候的返回是正常的,有时候又是204

dengao123 opened this issue · comments

  1. Your software version (Screenshot of your startup)

    Software Version
    PHP 7.4.21
    Swoole 4.8.12
    Laravel 5.7.26
  2. Detail description about this issue(error/log)
    前后端分离的项目,单独的网页请求是正常的,前端跨域请求就会偶尔报204错误。我加了日志后发现,
    发现:在\vendor\hhxsv5\laravel-s\src\Illuminate\Laravel.php的handleDynamic()中

public function handleDynamic(IlluminateRequest $request) {

    ob_start();
    if ($this->conf['is_lumen']) {
           ....
    } else {
        $response = $this->kernel->handle($request);
        $content = $response->getContent();
        app('log')->info('kernel get content is '. json_encode($content));    //这里打印的content偶尔为空值,所以返回给前端显示204
        $this->kernel->terminate($request, $response);
    }
    // prefer content in response, secondly ob
    if (!($response instanceof StreamedResponse) && (string)$content === '' && ob_get_length() > 0) {
        $response->setContent(ob_get_contents());
    }
    ob_end_clean();
    return $response;
}