Merge branch 'master' of https://github.com/maxious/ACTBus-ui
[busui.git] / lib / rolling-curl / .svn / text-base / example.php.svn-base
maxious 1 <?php
2 /*
3 authored by Josh Fraser (www.joshfraser.com)
4 released under Apache License 2.0
5
6 Maintained by Alexander Makarov, http://rmcreative.ru/
7
8 $Id$
9 */
10
11 require("RollingCurl.php");
12
13 // a little example that fetches a bunch of sites in parallel and echos the page title and response info for each request
14 function request_callback($response, $info, $request) {
15 // parse the page title out of the returned HTML
16 if (preg_match("~<title>(.*?)</title>~i", $response, $out)) {
17 $title = $out[1];
18 }
19 echo "<b>$title</b><br />";
20 print_r($info);
21 print_r($request);
22 echo "<hr>";
23 }
24
25 // single curl request
26 $rc = new RollingCurl("request_callback");
27 $rc->request("http://www.msn.com");
28 $rc->execute();
29
30 // another single curl request
31 $rc = new RollingCurl("request_callback");
32 $rc->request("http://www.google.com");
33 $rc->execute();
34
35 echo "<hr>";
36
37 // top 20 sites according to alexa (11/5/09)
38 $urls = array("http://www.google.com",
39 "http://www.facebook.com",
40 "http://www.yahoo.com",
41 "http://www.youtube.com",
42 "http://www.live.com",
43 "http://www.wikipedia.com",
44 "http://www.blogger.com",
45 "http://www.msn.com",
46 "http://www.baidu.com",
47 "http://www.yahoo.co.jp",
48 "http://www.myspace.com",
49 "http://www.qq.com",
50 "http://www.google.co.in",
51 "http://www.twitter.com",
52 "http://www.google.de",
53 "http://www.microsoft.com",
54 "http://www.google.cn",
55 "http://www.sina.com.cn",
56 "http://www.wordpress.com",
57 "http://www.google.co.uk");
58
59 $rc = new RollingCurl("request_callback");
60 $rc->window_size = 20;
61 foreach ($urls as $url) {
62 $request = new RollingCurlRequest($url);
63 $rc->add($request);
64 }
65 $rc->execute();
66