1
<?php
2
// create both cURL resources
3
$ch1 = curl_init();
4
$ch2 = curl_init();
5
6
// set URL and other appropriate options
7
curl_setopt($ch1, CURLOPT_URL, "http://m.baidu.com/");
8
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
9
10
curl_setopt($ch2, CURLOPT_URL, "http://www.baidu.com/");
11
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
12
13
//create the multiple cURL handle
14
$mh = curl_multi_init();
15
16
//add the two handles
17
curl_multi_add_handle($mh,$ch1);
18
curl_multi_add_handle($mh,$ch2);
19
20
$active = null;
21
//execute the handles
22
do {
23
$mrc = curl_multi_exec($mh, $active);
24
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
25
26
while ($active && $mrc == CURLM_OK) {
27
if (curl_multi_select($mh) != -1) {
28
do {
29
$mrc = curl_multi_exec($mh, $active);
30
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
31
}
32
}
33
34
//close the handles
35
curl_multi_remove_handle($mh, $ch1);
36
curl_multi_remove_handle($mh, $ch2);
37
curl_multi_close($mh);