多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# Coroutine\Http2\Client->write 向服务器发送更多数据帧,可以多次调用`write`向同一个`stream`写入数据帧。 ```php function Coroutine\Http2\Client->write(int $streamId, mixed $data, bool $end = false); ``` * `$streamId` 流编号,由`send`方法返回 * `$data`数据帧的内容,可以为字符串或数组 * `$end` 是否关闭流 注意事项 ----- * 如果要使用`write`分段发送数据帧,必须在`send`请求时将`$request->pipeline`设置为`true` * 当发送`end`为`true`的数据帧之后,流将关闭。之后不能再调用`write`向此`stream`发送数据 使用实例 ---- ```php use Swoole\Coroutine as co; co::create(function () use ($fp) { $cli = new co\Http2\Client('127.0.0.1', 9518); $cli->set([ 'timeout' => 1]); var_dump($cli->connect()); $req3 = new co\Http2\Request; $req3->path = "/index.php"; $req3->headers = [ 'host' => "localhost", "user-agent" => 'Chrome/49.0.2587.3', 'accept' => 'text/html,application/xhtml+xml,application/xml', 'accept-encoding' => 'gzip', ]; $req3->pipeline = true; $req3->method = "POST"; $streamId = $cli->send($req3); $cli->write($streamId, ['int' => rand(1000, 9999)]); $cli->write($streamId, ['int' => rand(1000, 9999)]); //end stream $cli->write($streamId, ['int' => rand(1000, 9999), 'end' => true], true); var_dump($cli->recv()); $cli->close(); }); ```