-
Notifications
You must be signed in to change notification settings - Fork 502
Expand file tree
/
Copy pathmultiple.php
More file actions
53 lines (46 loc) · 1.3 KB
/
multiple.php
File metadata and controls
53 lines (46 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* Requests for PHP, an HTTP library.
*
* @package Requests\Examples
* @copyright 2012-2023 Requests Contributors
* @license https://github.com/WordPress/Requests/blob/stable/LICENSE ISC
* @link https://github.com/WordPress/Requests
*/
// First, include the Requests Autoloader.
require_once dirname(__DIR__) . '/src/Autoload.php';
// Next, make sure Requests can load internal classes.
WpOrg\Requests\Autoload::register();
// Setup what we want to request
$requests = [
[
'url' => 'http://httpbin.org/get',
'headers' => ['Accept' => 'application/javascript'],
],
'post' => [
'url' => 'http://httpbin.org/post',
'data' => ['mydata' => 'something'],
],
'delayed' => [
'url' => 'http://httpbin.org/delay/10',
'options' => [
'timeout' => 20,
],
],
];
// Setup a callback
function my_callback(&$request, $id) {
var_dump($id, $request);
}
// Tell Requests to use the callback
$options = [
'complete' => 'my_callback',
];
// Send the request!
$responses = WpOrg\Requests\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);