From a02e6c4e4da0eb753512373f2794cc7555b8ff90 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Thu, 12 Feb 2015 18:51:23 +0700 Subject: [PATCH] Update multi curl example in readme; Add multi curl examples --- README.md | 34 +++++++++++++-------------- examples/multi_curl_delete.php | 17 ++++++++++++++ examples/multi_curl_get.php | 20 ++++++++++++++++ examples/multi_curl_get_callbacks.php | 33 ++++++++++++++++++++++++++ examples/multi_curl_patch.php | 19 +++++++++++++++ examples/multi_curl_post.php | 21 +++++++++++++++++ examples/multi_curl_put.php | 21 +++++++++++++++++ 7 files changed, 148 insertions(+), 17 deletions(-) create mode 100644 examples/multi_curl_delete.php create mode 100644 examples/multi_curl_get.php create mode 100644 examples/multi_curl_get_callbacks.php create mode 100644 examples/multi_curl_patch.php create mode 100644 examples/multi_curl_post.php create mode 100644 examples/multi_curl_put.php diff --git a/README.md b/README.md index 28cda27..d596a30 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/multi_curl_delete.php b/examples/multi_curl_delete.php new file mode 100644 index 0000000..70ba565 --- /dev/null +++ b/examples/multi_curl_delete.php @@ -0,0 +1,17 @@ +addDelete('https://httpbin.org/delete', array( + 'id' => '123', +)); +$multi_curl->addDelete('https://httpbin.org/delete', array( + 'id' => '456', +)); + +$multi_curl->start(); diff --git a/examples/multi_curl_get.php b/examples/multi_curl_get.php new file mode 100644 index 0000000..15bce21 --- /dev/null +++ b/examples/multi_curl_get.php @@ -0,0 +1,20 @@ +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(); diff --git a/examples/multi_curl_get_callbacks.php b/examples/multi_curl_get_callbacks.php new file mode 100644 index 0000000..5426520 --- /dev/null +++ b/examples/multi_curl_get_callbacks.php @@ -0,0 +1,33 @@ +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(); diff --git a/examples/multi_curl_patch.php b/examples/multi_curl_patch.php new file mode 100644 index 0000000..16305bd --- /dev/null +++ b/examples/multi_curl_patch.php @@ -0,0 +1,19 @@ +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(); diff --git a/examples/multi_curl_post.php b/examples/multi_curl_post.php new file mode 100644 index 0000000..447ff34 --- /dev/null +++ b/examples/multi_curl_post.php @@ -0,0 +1,21 @@ +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(); diff --git a/examples/multi_curl_put.php b/examples/multi_curl_put.php new file mode 100644 index 0000000..90e899d --- /dev/null +++ b/examples/multi_curl_put.php @@ -0,0 +1,21 @@ +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();