Skip to content

Commit 80f874b

Browse files
committed
Add multicurl download example with success, error, and complete callbacks
1 parent bd75d8a commit 80f874b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
require __DIR__ . '/vendor/autoload.php';
3+
4+
use \Curl\MultiCurl;
5+
6+
$multi_curl = new MultiCurl();
7+
$multi_curl->success(function ($instance) {
8+
echo 'call to "' . $instance->url . '" was successful.' . "\n";
9+
});
10+
$multi_curl->error(function ($instance) {
11+
echo 'call to "' . $instance->url . '" was unsuccessful.' . "\n";
12+
echo 'error code: ' . $instance->errorCode . "\n";
13+
echo 'error message: ' . $instance->errorMessage . "\n";
14+
});
15+
$multi_curl->complete(function ($instance) {
16+
echo 'call to "' . $instance->url . '" completed.' . "\n";
17+
});
18+
19+
$multi_curl->addDownload('https://secure.php.net/images/logos/php-med-trans.png', '/tmp/php-med-trans.png');
20+
$multi_curl->addDownload('https://upload.wikimedia.org/wikipedia/commons/c/c1/PHP_Logo.png', '/tmp/PHP_Logo.png');
21+
$multi_curl->start();

examples/multi_curl_get_callbacks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
echo 'error message: ' . $instance->errorMessage . "\n";
1616
});
1717
$multi_curl->complete(function ($instance) {
18-
echo 'call completed' . "\n";
18+
echo 'call to "' . $instance->url . '" completed.' . "\n";
1919
});
2020

2121
$multi_curl->addGet('https://www.google.com/search', array(

0 commit comments

Comments
 (0)