Parallelise http transfers for trip planner tester
[busui.git] / lib / rolling-curl / example_groups.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
44
45
46
47
48
49
<?php
require 'RollingCurl.php';
require 'RollingCurlGroup.php';
 
class TestCurlRequest extends RollingCurlGroupRequest {
    public $test_verbose = true;
 
    function process($output, $info) {
        echo "Processing " . $this->url . "\n";
        if ($this->test_verbose)
            print_r($info);
 
        parent::process($output, $info);
    }
}
 
class TestCurlGroup extends RollingCurlGroup {
    function process($output, $info, $request) {
        echo "Group CB: Progress " . $this->name . " (" . ($this->finished_requests + 1) . "/" . $this->num_requests . ")\n";
        parent::process($output, $info, $request);
    }
 
    function finished() {
        echo "Group CB: Finished" . $this->name . "\n";
        parent::finished();
    }
}
 
$group = new TestCurlGroup("High");
$group->add(new TestCurlRequest("www.google.de"));
$group->add(new TestCurlRequest("www.yahoo.de"));
$group->add(new TestCurlRequest("www.newyorktimes.com"));
$reqs[] = $group;
 
$group = new TestCurlGroup("Normal");
$group->add(new TestCurlRequest("twitter.com"));
$group->add(new TestCurlRequest("www.bing.com"));
$group->add(new TestCurlRequest("m.facebook.com"));
$reqs[] = $group;
 
$reqs[] = new TestCurlRequest("www.kernel.org");
 
// No callback here, as its done in Request class
$rc = new GroupRollingCurl();
 
foreach ($reqs as $req)
    $rc->add($req);
 
$rc->execute();