mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-27 18:50:43 +00:00
Update multi curl example in readme; Add multi curl examples
This commit is contained in:
@@ -116,32 +116,32 @@ curl_close($curl->curl);
|
||||
|
||||
```php
|
||||
// Requests in parallel with callback functions.
|
||||
$curl = new Curl();
|
||||
$curl->setUserAgent('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1');
|
||||
$multi_curl = new MultiCurl();
|
||||
|
||||
$curl->success(function($instance) {
|
||||
echo 'call to "' . $instance->url . '" was successful. response was' . "\n";
|
||||
echo $instance->response . "\n";
|
||||
$multi_curl->success(function($instance) {
|
||||
echo 'call to "' . $instance->url . '" was successful.' . "\n";
|
||||
echo 'response: ' . $instance->response . "\n";
|
||||
});
|
||||
$curl->error(function($instance) {
|
||||
$multi_curl->error(function($instance) {
|
||||
echo 'call to "' . $instance->url . '" was unsuccessful.' . "\n";
|
||||
echo 'error code:' . $instance->error_code . "\n";
|
||||
echo 'error message:' . $instance->error_message . "\n";
|
||||
echo 'error code: ' . $instance->error_code . "\n";
|
||||
echo 'error message: ' . $instance->error_message . "\n";
|
||||
});
|
||||
$curl->complete(function($instance) {
|
||||
$multi_curl->complete(function($instance) {
|
||||
echo 'call completed' . "\n";
|
||||
});
|
||||
|
||||
$curl->get(array(
|
||||
'https://duckduckgo.com/',
|
||||
'https://search.yahoo.com/search',
|
||||
'https://www.bing.com/search',
|
||||
'http://www.dogpile.com/search/web',
|
||||
'https://www.google.com/search',
|
||||
'https://www.wolframalpha.com/input/',
|
||||
), array(
|
||||
$multi_curl->addGet('https://www.google.com/search', array(
|
||||
'q' => 'hello world',
|
||||
));
|
||||
$multi_curl->addGet('https://duckduckgo.com/', array(
|
||||
'q' => 'hello world',
|
||||
));
|
||||
$multi_curl->addGet('https://www.bing.com/search', array(
|
||||
'q' => 'hello world',
|
||||
));
|
||||
|
||||
$multi_curl->start();
|
||||
```
|
||||
|
||||
### Available Methods
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
require '../src/Curl/Curl.php';
|
||||
require '../src/Curl/MultiCurl.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
use \Curl\MultiCurl;
|
||||
|
||||
$multi_curl = new MultiCurl();
|
||||
|
||||
$multi_curl->addDelete('https://httpbin.org/delete', array(
|
||||
'id' => '123',
|
||||
));
|
||||
$multi_curl->addDelete('https://httpbin.org/delete', array(
|
||||
'id' => '456',
|
||||
));
|
||||
|
||||
$multi_curl->start();
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require '../src/Curl/Curl.php';
|
||||
require '../src/Curl/MultiCurl.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
use \Curl\MultiCurl;
|
||||
|
||||
$multi_curl = new MultiCurl();
|
||||
|
||||
$multi_curl->addGet('https://www.google.com/search', array(
|
||||
'q' => 'hello world',
|
||||
));
|
||||
$multi_curl->addGet('https://duckduckgo.com/', array(
|
||||
'q' => 'hello world',
|
||||
));
|
||||
$multi_curl->addGet('https://www.bing.com/search', array(
|
||||
'q' => 'hello world',
|
||||
));
|
||||
|
||||
$multi_curl->start();
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
require '../src/Curl/Curl.php';
|
||||
require '../src/Curl/MultiCurl.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
use \Curl\MultiCurl;
|
||||
|
||||
$multi_curl = new MultiCurl();
|
||||
|
||||
$multi_curl->success(function($instance) {
|
||||
echo 'call to "' . $instance->url . '" was successful.' . "\n";
|
||||
echo 'response: ' . $instance->response . "\n";
|
||||
});
|
||||
$multi_curl->error(function($instance) {
|
||||
echo 'call to "' . $instance->url . '" was unsuccessful.' . "\n";
|
||||
echo 'error code: ' . $instance->error_code . "\n";
|
||||
echo 'error message: ' . $instance->error_message . "\n";
|
||||
});
|
||||
$multi_curl->complete(function($instance) {
|
||||
echo 'call completed' . "\n";
|
||||
});
|
||||
|
||||
$multi_curl->addGet('https://www.google.com/search', array(
|
||||
'q' => 'hello world',
|
||||
));
|
||||
$multi_curl->addGet('https://duckduckgo.com/', array(
|
||||
'q' => 'hello world',
|
||||
));
|
||||
$multi_curl->addGet('https://www.bing.com/search', array(
|
||||
'q' => 'hello world',
|
||||
));
|
||||
|
||||
$multi_curl->start();
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require '../src/Curl/Curl.php';
|
||||
require '../src/Curl/MultiCurl.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
use \Curl\MultiCurl;
|
||||
|
||||
$multi_curl = new MultiCurl();
|
||||
|
||||
$multi_curl->addPatch('https://httpbin.org/patch', array(
|
||||
'id' => '123',
|
||||
'body' => 'hello world!',
|
||||
));
|
||||
$multi_curl->addPatch('https://httpbin.org/patch', array(
|
||||
'id' => '456',
|
||||
'body' => 'hello world!',
|
||||
));
|
||||
|
||||
$multi_curl->start();
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
require '../src/Curl/Curl.php';
|
||||
require '../src/Curl/MultiCurl.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
use \Curl\MultiCurl;
|
||||
|
||||
$multi_curl = new MultiCurl();
|
||||
|
||||
$multi_curl->addPost('https://httpbin.org/post', array(
|
||||
'to' => 'alice',
|
||||
'subject' => 'hi',
|
||||
'body' => 'hi Alice',
|
||||
));
|
||||
$multi_curl->addPost('https://httpbin.org/post', array(
|
||||
'to' => 'bob',
|
||||
'subject' => 'hi',
|
||||
'body' => 'hi Bob',
|
||||
));
|
||||
|
||||
$multi_curl->start();
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
require '../src/Curl/Curl.php';
|
||||
require '../src/Curl/MultiCurl.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
use \Curl\MultiCurl;
|
||||
|
||||
$multi_curl = new MultiCurl();
|
||||
|
||||
$multi_curl->addPut('https://httpbin.org/put', array(
|
||||
'id' => '123',
|
||||
'subject' => 'hello',
|
||||
'body' => 'hello',
|
||||
));
|
||||
$multi_curl->addPut('https://httpbin.org/put', array(
|
||||
'id' => '456',
|
||||
'subject' => 'hello',
|
||||
'body' => 'hello',
|
||||
));
|
||||
|
||||
$multi_curl->start();
|
||||
Reference in New Issue
Block a user