时间:2021-07-01 10:21:17 帮助过:28人阅读
代码如下:
<?php
$text = remote(array('http://www.gxlcms.com/','http://www.baidu.com/'));
print_r($text);
function remote($urls) {
if (!is_array($urls) or count($urls) == 0) {
return false;
}
$curl = $text = array();
$handle = curl_multi_init();
foreach($urls as $k => $v) {
$nurl[$k]= preg_replace('~([^:\/\.]+)~ei', "rawurlencode('\\1')", $v);
$curl[$k] = curl_init($nurl[$k]);
curl_setopt($curl[$k], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl[$k], CURLOPT_HEADER, 0);
curl_multi_add_handle ($handle, $curl[$k]);
}
$active = null;
do {
$mrc = curl_multi_exec($handle, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($handle) != -1) {
do {
$mrc = curl_multi_exec($handle, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
foreach ($curl as $k => $v) {
if (curl_error($curl[$k]) == "") {
$text[$k] = (string) curl_multi_getcontent($curl[$k]);
}
curl_multi_remove_handle($handle, $curl[$k]);
curl_close($curl[$k]);
}
curl_multi_close($handle);
return $text;
}