Skip to content

Commit ca69ece

Browse files
committed
Add parallel requests and callback example to README
1 parent cdeb589 commit ca69ece

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,33 @@ $curl->close();
8484
curl_set_opt($curl->curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1');
8585
curl_close($curl->curl);
8686
```
87+
88+
```php
89+
// Requests in parallel with callback functions.
90+
$curl = new Curl();
91+
$curl->setOpt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1');
92+
93+
$curl->success(function($instance) {
94+
echo 'call was successful. response was' . "\n";
95+
echo $instance->response . "\n";
96+
});
97+
$curl->error(function($instance) {
98+
echo 'call was unsuccessful.' . "\n";
99+
echo 'error code:' . $instance->error_code . "\n";
100+
echo 'error message:' . $instance->error_message . "\n";
101+
});
102+
$curl->complete(function($instance) {
103+
echo 'call completed' . "\n";
104+
});
105+
106+
$curl->get(array(
107+
'https://duckduckgo.com/',
108+
'https://search.yahoo.com/search',
109+
'http://www.bing.com/search',
110+
'http://www.dogpile.com/search/web',
111+
'https://www.google.com/search',
112+
'https://www.wolframalpha.com/input/',
113+
), array(
114+
'q' => 'hello world',
115+
));
116+
```

0 commit comments

Comments
 (0)