OpenSwoole\Coroutine\Http2\Client->recv(...)

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Coroutine\Http2\Client->recv(float $timeout): OpenSwoole\Http2\Response

Parameters

timeout

In seconds, the timeout of the request, 1.5 means 1.5 seconds. See the timeout guide link below.

Return

Returns a client OpenSwoole\Http2\Response object when successful and false when not, check $client->errCode for more details upon an error.


Description

Receive a response from the remote host.

When using this method, while waiting for IO OpenSwoole will switch coroutines so resources are not wasted and return upon a response or failure.

The built in HTTP clients have a timeout option, allowing you to wait for a response, the timeout can be set in a few different ways, refer to the timeout guide for more information. However, the $timeout parameter will work in most cases.


Response HTTP/2 Object

This method returns a OpenSwoole\Http2\Response object which is a class with no methods, only public class properties which you can access, see the response object documentation for more details and what it contains. This object is only returned on a successful response. Check $client->errCode if you receive false.


Example

Check the main Quick Start Examples to see how the recv() method is used in its full context.

Last updated on September 1, 2022