-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from rmccue/multiple
Add ability to send multiple requests at once
- Loading branch information
Showing
7 changed files
with
574 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
// First, include Requests | ||
include('../library/Requests.php'); | ||
|
||
// Next, make sure Requests can load internal classes | ||
Requests::register_autoloader(); | ||
|
||
// Setup what we want to request | ||
$requests = array( | ||
array( | ||
'url' => 'http://httpbin.org/get', | ||
'headers' => array('Accept' => 'application/javascript'), | ||
), | ||
'post' => array( | ||
'url' => 'http://httpbin.org/post', | ||
'data' => array('mydata' => 'something'), | ||
), | ||
'delayed' => array( | ||
'url' => 'http://httpbin.org/delay/10', | ||
'options' => array( | ||
'timeout' => 20, | ||
), | ||
), | ||
); | ||
|
||
// Setup a callback | ||
function my_callback(&$request, $id) { | ||
var_dump($id, $request); | ||
} | ||
|
||
// Tell Requests to use the callback | ||
$options = array( | ||
'complete' => 'my_callback', | ||
); | ||
|
||
// Send the request! | ||
$responses = Requests::request_multiple($requests, $options); | ||
|
||
// Note: the response from the above call will be an associative array matching | ||
// $requests with the response data, however we've already handled it in | ||
// my_callback() anyway! | ||
// | ||
// If you don't believe me, uncomment this: | ||
# var_dump($responses); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.