think\Response::send PHP Method

send() public method

发送数据到客户端
public send ( ) : mixed
return mixed
    public function send()
    {
        // 处理输出数据
        $data = $this->getContent();
        // Trace调试注入
        if (Env::get('app_trace', Config::get('app_trace'))) {
            Debug::inject($this, $data);
        }
        if (!headers_sent() && !empty($this->header)) {
            // 发送状态码
            http_response_code($this->code);
            // 发送头部信息
            foreach ($this->header as $name => $val) {
                header($name . ':' . $val);
            }
        }
        if (200 == $this->code) {
            $cache = Request::instance()->getCache();
            if ($cache) {
                header('Cache-Control: max-age=' . $cache[1] . ',must-revalidate');
                header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
                header('Expires:' . gmdate('D, d M Y H:i:s', $_SERVER['REQUEST_TIME'] + $cache[1]) . ' GMT');
                $header['Content-Type'] = $this->header['Content-Type'];
                Cache::set($cache[0], [$data, $header], $cache[1]);
            }
        }
        echo $data;
        if (function_exists('fastcgi_finish_request')) {
            // 提高页面响应
            fastcgi_finish_request();
        }
        // 监听response_end
        Hook::listen('response_end', $this);
    }

Usage Example

Example #1
0
 /**
  * @covers think\Response::tramsform
  * @todo Implement testTramsform().
  */
 public function testTramsform()
 {
     Response::tramsform(function () {
         return "callbackreturndata";
     });
     $dataArr = [];
     $result = Response::send($dataArr, "", true);
     $this->assertEquals("callbackreturndata", $result);
     Response::tramsform(null);
 }
All Usage Examples Of think\Response::send