Join 4,000+ others and never miss out on new tips, tutorials, and more.
pecl install openswoole-22.0.0 | composer require openswoole/core:22.1.2
<?php OpenSwoole\Coroutine\Http2\Client->read(float $timeout): OpenSwoole\Http2\Response
In seconds, the timeout of the request, 1.5 means 1.5 seconds. See the timeout guide link below.
Returns a client
OpenSwoole\Http2\Response object when successful and
false when not, check
$client->errCode for more details upon an error.
Receive multiple responses 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.
Differences with recv()
read() method is basically the same as
recv() but the difference being, you can use
read() to receive multiple responses from a stream. A successful response will always return
When receiving multiple
read() responses, you must have used the
$request->pipeline = true option so that a stream is kept open, allowing you to keep reading, see the
write() method documentation for more details on using the
This method will always return a complete (whole) response, everything is read into memory first before returning.
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