Http\Response::create
最后更新于:2022-04-02 06:33:48
# Http\\Response::create
构造新的`Http\Response`对象。使用此方法前请务必调用`detach`方法将旧的`$response`对象分离,否则可能会造成对同一个请求发送两次响应内容。
~~~
function Http\Response::create(int $fd) : Http\Response;
~~~
* 参数为需要绑定的连接`$fd`,调用`Http\Response`对象的`end`与`write`方法时会向此连接发送数据
* 调用成功返回一个新的`Http\Response`对象,调用失败返回`false`
> 需要`2.2.0`或更高版本
~~~
$http = new Swoole\Http\Server("0.0.0.0", 9501);
$http->on('request', function ($req, Swoole\Http\Response $resp) use ($http) {
$resp->detach();
$resp2 = Swoole\Http\Response::create($req->fd);
$resp2->end("hello world");
});
$http->start();
~~~
';