Skip to content

Commit 9187b59

Browse files
authored
Create retry_package.mdx
1 parent 41fbef4 commit 9187b59

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

pages/php/retry_package.mdx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Retry — Quick Guide
2+
3+
A tiny PHP helper to wrap any callable with a retry algorithm. It helps you handle transient failures (like flaky network or temporary DB issues) by retrying your code a few times before giving up.
4+
5+
Source code: https://github.com/GeorgII-web/Retry
6+
7+
## Basic usage
8+
9+
```php
10+
use GeorgII\Retry;
11+
12+
// Retry on any exception (default settings)
13+
$result = Retry::onAnyException(fn () => someOperation());
14+
```
15+
16+
## With options
17+
18+
```php
19+
use GeorgII\Retry;
20+
use GeorgII\Event\RetryEvent;
21+
22+
$result = Retry::onAnyException(
23+
attemptCallback: function (RetryEvent $event) {
24+
return someOperation($event);
25+
},
26+
retryCount: 3, // how many times to retry
27+
retryDelay: 0.2, // seconds between attempts (can be a Closure for backoff)
28+
eventCallback: function (RetryEvent $event) {
29+
// observe events if you need
30+
// var_dump($event->getName(), $event->getAttempt());
31+
}
32+
);
33+
```
34+
35+
## Using your own alias (example)
36+
37+
If you commonly retry specific exceptions, wrap them in an alias in your project and call it directly:
38+
39+
```php
40+
use GeorgII\Retry;
41+
42+
$users = Retry::onDbException(fn () => $sql->query('SELECT * FROM users'));
43+
```
44+
45+
That's it — simple, small, and focused on retriable errors only.

0 commit comments

Comments
 (0)