forked from adawley/php-curl-queue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
74 lines (63 loc) · 1.91 KB
/
example.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
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
// include the class
require_once("CurlQueue.class.php");
// define the callback functions
function mycallback($output,$info)
{
$url = $info["url"];
echo "Received output from $url.<br />";
var_dump($info);
echo "<br /><br />";
}
function anothercallback($output,$info)
{
$url = $info["url"];
echo "Custom callbacks can be set for each request. Here's an example. Received output from $url<br />";
var_dump($info);
echo "<br /><br />";
}
class foo
{
public function classcallback($output,$info)
{
$url = $info["url"];
echo "Callbacks can be inside classes. Here's an example. Received output from $url<br />";
var_dump($info);
echo "<br /><br />";
}
}
$foo = new foo();
$curl = new CurlQueue;
$config = array(
"window" => 5,
"timeout" => 10,
"callback" => "mycallback"
);
$curl->config($config);
// HTTPS hosts
$curl->get("https://www.google.com");
$curl->get("http://www.yahoo.com");
$curl->get("http://www.msn.com");
$curl->get("http://www.microsoft.com");
$curl->get("http://www.espn.com");
// POST instead of GET
$curl->post("http://www.cnn.com");
$curl->get("http://www.npr.org");
$curl->get("http://www.nbc.com");
$curl->get("http://www.twitter.com");
$curl->get("http://www.reddit.com");
$curl->get("http://www.metafilter.com");
$curl->get("http://www.netflix.com");
$curl->get("http://www.nytimes.com");
// custom callback
$curl->get("http://www.slashdot.org",NULL,NULL,"anothercallback");
// callback in a class
$curl->get("http://www.news.google.com",NULL,NULL,array($foo,"classcallback"));
if ( $result = $curl->execute() ) echo "All requests have been processed.";
else echo "An error occured that prevented processing of all requests.";
echo "<br /><br />";
echo "If only one request is submitted, a callback function is not necessary. Execute will return the curl output instead of the normal status boolean.<br />";
echo var_dump($result);
?>