werkint / reactphp-http-client
This package is abandoned and no longer maintained.
The author suggests using the werkint/reactphp-http-client package instead.
Asynchronous HTTP client library.
v0.4.14
2016-10-28 18:03 UTC
Requires
- php: >=5.4.0
- evenement/evenement: ~2.0
- guzzlehttp/psr7: ^1.0
- react/dns: 0.4.*
- react/event-loop: 0.4.*
- react/promise: ~2.2
- react/socket-client: ^0.5 || ^0.4 || ^0.3
- react/stream: 0.4.*
This package is not auto-updated.
Last update: 2019-02-20 19:05:52 UTC
README
Basic HTTP/1.0 client.
Basic usage
Requests are prepared using the Client#request()
method. Body can be
sent with Request#write()
. Request#end()
finishes sending the request
(or sends it at all if no body was written).
Request implements WritableStreamInterface, so a Stream can be piped to it. Response implements ReadableStreamInterface.
Interesting events emitted by Request:
response
: The response headers were received from the server and successfully parsed. The first argument is a Response instance.error
: An error occurred.end
: The request is finished. If an error occurred, it is passed as first argument. Second and third arguments are the Response and the Request.
Interesting events emitted by Response:
data
: Passes a chunk of the response body as first argument and a Response object itself as second argument. When a response encounters a chunked encoded response it will parse it transparently for the user ofResponse
and removing theTransfer-Encoding
header.error
: An error occurred.end
: The response has been fully received. If an error occurred, it is passed as first argument.
Example
<?php $loop = React\EventLoop\Factory::create(); $dnsResolverFactory = new React\Dns\Resolver\Factory(); $dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop); $factory = new React\HttpClient\Factory(); $client = $factory->create($loop, $dnsResolver); $request = $client->request('GET', 'https://github.com/'); $request->on('response', function ($response) { $response->on('data', function ($data, $response) { // ... }); }); $request->end(); $loop->run();
See also the examples.
TODO
- gzip content encoding
- keep-alive connections
- following redirections