MojoX-HTTP-Async
view release on metacpan or search on metacpan
if (my $error = $tx->req()->error()) {
say $error->{code};
say $error->{message};
}
# how to process request timeouts and other errors sucn as broken pipes, etc
if (my $error = $tx->res()->error()) {
say $error->{code};
say $error->{message};
}
# makes reconnection if either slot was timeouted or was inactive too long
$ua->refresh_connections();
# closes everything
$ua->close_all();
DESCRIPTION
This library allows to make multiple HTTP/HTTPS request to the
particular host in non-blocking mode.
In comparison with HTTP::Async, this library doesn't make a new
connection on each request.
And in comparison with Mojo::AsyncAwait, it's more intuitive how
to use it, and there is no any Singleton restrictions.
The instance of this class can work only with one domain and scheme:
either HTTP or HTTPS.
LICENSE
This module is distributed under terms of Artistic Perl 5 license.
new($class, %opts)
The class constructor.
host
It's the obligatory option. Sets the name/address of remote host to be
requested.
port
By default it's equal to 80. Sets the port number of remote point.
slots
By default it's equal to 5. Sets the maximum amount of slots. These
slot will be filled one by one if required.
ssl
By default it's equal to 0 (means HTTP). Sets the scheme of requests:
HTTP or HTTPS.
ssl_opts
It's a HashRef with options to control SSL Layer. See IO::Socket::SSL
constructor arguments for details.
connect_timeout
By default it's equal to 1. Sets connection timeout in seconds.
If it's equal to 0, then there will be no timeout restrictions.
request_timeout
By default it's equal to 1. Sets the time in seconds with granular
accuracy as micro seconds. The awaiting time of response will be
limited with this value.
In case of 0 value there will be no time restrictions.
sol_socket
It's a HashRef with socket options. The possible keys are:
so_keepalive - enables TCP KeepAlive on socket.
The default value is 1 (means that option is enabled).
sol_tcp
WARNING: These options can be unsupported on some OS platforms.
It's a HashRef with socket TCP-options.
If some key is absent in HashRef then system settings will be used.
The supported keys are shown below:
tcp_keepidle - the time (in seconds) the connection needs to remain
idle before TCP starts sending keepalive probes
tcp_keepintvl - the time (in seconds) between individual keepalive
probes
tcp_keepcnt - the maximum number of keepalive probes TCP should send
before dropping the connection.
inactivity_conn_ts
If last response was received inactivity_conn_ts seconds or more ago,
then such slots will be destroyed.
By default the value is 0 (disabled).
debug
Enables debug mode. The dbug messages will be printed in STDERR. By
default the value is 0 (disabled).
add ($self, $request_or_uri, $timeout = undef)
Adds HTTP request into empty slot.
If the request was successfully added, then it will return 1. Otherwise
it will return 0.
( run in 0.570 second using v1.01-cache-2.11-cpan-39bf76dae61 )