kelunik / retry
A tiny library for retrying failed operations.
Installs: 15 532
Dependents: 7
Suggesters: 0
Security: 0
Stars: 15
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- amphp/amp: ^2
Requires (Dev)
- amphp/socket: ^0.10.2
- friendsofphp/php-cs-fixer: ^2.3
- phpunit/phpunit: ^6
This package is auto-updated.
Last update: 2024-10-25 10:47:18 UTC
README
kelunik/retry
is a small library for retrying failed operations.
Installation
composer require kelunik/retry
Usage
<?php use Amp\Loop; use Kelunik\Retry\ConstantBackoff; use function Kelunik\Retry\retry; require __DIR__ . "/../vendor/autoload.php"; Loop::run(function () { /** @var Amp\Socket\ClientSocket $socket */ $socket = yield retry(3, function () { return Amp\Socket\cryptoConnect("tcp://github.com:443"); }, Amp\Socket\SocketException::class, new ConstantBackoff(1000)); yield $socket->write("GET / HTTP/1.0\r\nhost: github.com\r\n\r\n"); $buffer = ""; while (null !== $chunk = yield $socket->read()) { $buffer .= $chunk; if (strpos($buffer, "\r\n\r\n") !== false) { print strstr($buffer, "\r\n\r\n", true); break; } } $socket->close(); });