企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Coroutine\Http\Client->recv 接收消息。与`setDefer`或`upgrade`配合使用。 ```php function Coroutine\Http\Client->recv(float $timeout = -1); ``` * `$timeout` 为`upgrade`升级为websocket时可用的超时参数 * `$timeout` 设置超时,优先使用指定的参数,其次使用`set`方法中传入的`timeout`配置 * 未设置任何超时,将持续等待 > `$timeout`参数需要`2.1.2`或更高版本 Http ----- ```php go(function () { $cli = new Swoole\Coroutine\Http\Client('127.0.0.1', 80); $cli->setHeaders([ 'Host' => "localhost", "User-Agent" => 'Chrome/49.0.2587.3', 'Accept' => 'text/html,application/xhtml+xml,application/xml', 'Accept-Encoding' => 'gzip', ]); $cli->set([ 'timeout' => 1]); $cli->setDefer(); $cli->get('/'); co::sleep(1); $data = $cli->recv(); }); ``` WebSocket ---- ```php go(function () { $cli = new Co\http\Client("127.0.0.1", 9501); $ret = $cli->upgrade("/"); if ($ret) { while(true) { $cli->push("hello"); var_dump($cli->recv()); co::sleep(0.1); } } }); ```