-
Notifications
You must be signed in to change notification settings - Fork 101
/
test.php
executable file
·119 lines (105 loc) · 3.06 KB
/
test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/php
<?php
//
// A test script for the ParallelCurl class
//
// This example fetches a 100 different results from Google's search API, with no more
// than 10 outstanding at any time.
//
// By Pete Warden <[email protected]>, freely reusable, see http://petewarden.typepad.com for more
require_once('parallelcurl.php');
define ('SEARCH_URL_PREFIX', 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=large&filter=0');
// This function gets called back for each request that completes
function on_request_done($content, $url, $ch, $search) {
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpcode !== 200) {
print "Fetch error $httpcode for '$url'\n";
return;
}
$responseobject = json_decode($content, true);
if (empty($responseobject['responseData']['results'])) {
print "No results found for '$search'\n";
return;
}
print "********\n";
print "$search:\n";
print "********\n";
$allresponseresults = $responseobject['responseData']['results'];
foreach ($allresponseresults as $responseresult) {
$title = $responseresult['title'];
print "$title\n";
}
}
// The terms to search for on Google
$terms_list = array(
"John", "Mary",
"William", "Anna",
"James", "Emma",
"George", "Elizabeth",
"Charles", "Margaret",
"Frank", "Minnie",
"Joseph", "Ida",
"Henry", "Bertha",
"Robert", "Clara",
"Thomas", "Alice",
"Edward", "Annie",
"Harry", "Florence",
"Walter", "Bessie",
"Arthur", "Grace",
"Fred", "Ethel",
"Albert", "Sarah",
"Samuel", "Ella",
"Clarence", "Martha",
"Louis", "Nellie",
"David", "Mabel",
"Joe", "Laura",
"Charlie", "Carrie",
"Richard", "Cora",
"Ernest", "Helen",
"Roy", "Maude",
"Will", "Lillian",
"Andrew", "Gertrude",
"Jesse", "Rose",
"Oscar", "Edna",
"Willie", "Pearl",
"Daniel", "Edith",
"Benjamin", "Jennie",
"Carl", "Hattie",
"Sam", "Mattie",
"Alfred", "Eva",
"Earl", "Julia",
"Peter", "Myrtle",
"Elmer", "Louise",
"Frederick", "Lillie",
"Howard", "Jessie",
"Lewis", "Frances",
"Ralph", "Catherine",
"Herbert", "Lula",
"Paul", "Lena",
"Lee", "Marie",
"Tom", "Ada",
"Herman", "Josephine",
"Martin", "Fanny",
"Jacob", "Lucy",
"Michael", "Dora",
);
if (isset($argv[1])) {
$max_requests = $argv[1];
} else {
$max_requests = 10;
}
$curl_options = array(
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_USERAGENT, 'Parallel Curl test script',
);
$parallel_curl = new ParallelCurl($max_requests, $curl_options);
foreach ($terms_list as $terms) {
$search = '"'.$terms.' is a"';
$search_url = SEARCH_URL_PREFIX.'&q='.urlencode($terms);
$parallel_curl->startRequest($search_url, 'on_request_done', $search);
}
// This should be called when you need to wait for the requests to finish.
// This will automatically run on destruct of the ParallelCurl object, so the next line is optional.
$parallel_curl->finishAllRequests();
?>