-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.php
43 lines (35 loc) · 969 Bytes
/
sample.php
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
<?php
use wondernetwork\wiuphp;
require_once __DIR__.'/vendor/autoload.php';
/*
* set up the API with your client ID and token
*/
$api = new wiuphp\API('YOUR_CLIENT_ID', 'YOUR_CLIENT_TOKEN');
/*
* if you're using Memcached, you can cache results to avoid duplicate API
* calls using the MemcachedAPI decorator:
*/
$api = new wiuphp\MemcachedAPI(
new wiuphp\API('YOUR_CLIENT_ID', 'YOUR_CLIENT_TOKEN'),
new Memcached()
);
/*
* get the list of available edge servers
*/
$servers = $api->servers();
/*
* submit a new request to ping http://google.com from Denver and London
*/
$jobID = $api->submit('google.com', ['denver', 'london'], ['ping']);
/*
* retrieve the job results
*/
$job = $api->retrieve($jobID);
/*
* poll the job results for 10 seconds or until the results are complete
*/
$seconds = 0; $maxSeconds = 10;
do {
sleep(1);
$job = $api->retrieve($jobID);
} while ($job['response']['in_progress'] && $seconds++ < $maxSeconds);