Skip to content

Commit ab76ee5

Browse files
committed
Add examples for Curl::setRetry() and MultiCurl::setRetry()
1 parent 4ec89be commit ab76ee5

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
require __DIR__ . '/../vendor/autoload.php';
3+
4+
use \Curl\Curl;
5+
6+
$curl = new Curl();
7+
$curl->setRetry(function ($instance) {
8+
return $instance->retries < 3;
9+
});
10+
$curl->get('https://httpbin.org/status/503');
11+
12+
if ($curl->error) {
13+
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage . "\n";
14+
echo 'attempts: ' . $curl->attempts . "\n";
15+
echo 'retries: ' . $curl->retries . "\n";
16+
} else {
17+
echo 'Response:' . "\n";
18+
var_dump($curl->response);
19+
}

examples/get_with_retry.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
require __DIR__ . '/../vendor/autoload.php';
3+
4+
use \Curl\Curl;
5+
6+
$max_retries = 3;
7+
8+
$curl = new Curl();
9+
$curl->setRetry($max_retries);
10+
$curl->get('https://httpbin.org/status/503');
11+
12+
if ($curl->error) {
13+
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage . "\n";
14+
echo 'attempts: ' . $curl->attempts . "\n";
15+
echo 'retries: ' . $curl->retries . "\n";
16+
} else {
17+
echo 'Response:' . "\n";
18+
var_dump($curl->response);
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
require __DIR__ . '/../vendor/autoload.php';
3+
4+
use \Curl\MultiCurl;
5+
6+
$multi_curl = new MultiCurl();
7+
$multi_curl->setRetry(function ($instance) {
8+
return $instance->retries < 3;
9+
});
10+
$multi_curl->complete(function ($instance) {
11+
echo 'call to "' . $instance->url . '" completed.' . "\n";
12+
echo 'attempts: ' . $instance->attempts . "\n";
13+
echo 'retries: ' . $instance->retries . "\n";
14+
});
15+
16+
$multi_curl->addGet('https://httpbin.org/status/503?a');
17+
$multi_curl->addGet('https://httpbin.org/status/503?b');
18+
$multi_curl->addGet('https://httpbin.org/status/503?c');
19+
20+
$multi_curl->start();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
require __DIR__ . '/../vendor/autoload.php';
3+
4+
use \Curl\MultiCurl;
5+
6+
$max_retries = 3;
7+
8+
$multi_curl = new MultiCurl();
9+
$multi_curl->setRetry($max_retries);
10+
$multi_curl->complete(function ($instance) {
11+
echo 'call to "' . $instance->url . '" completed.' . "\n";
12+
echo 'attempts: ' . $instance->attempts . "\n";
13+
echo 'retries: ' . $instance->retries . "\n";
14+
});
15+
16+
$multi_curl->addGet('https://httpbin.org/status/503?a');
17+
$multi_curl->addGet('https://httpbin.org/status/503?b');
18+
$multi_curl->addGet('https://httpbin.org/status/503?c');
19+
20+
$multi_curl->start();

0 commit comments

Comments
 (0)