/** * 通过urls多线程下载图片 * @param array $urls * @return array */ private function MultiDownByUrls($urls) { $opts = array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_AUTOREFERER => 1, CURLOPT_HEADER => 0, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36'); $mutil = new MultiHttpRequest($urls, $opts); $mutil->start(); return $mutil->getRes(); }
if (count($pages) != 2) { continue; } $urls = array(); for ($i = $pages[0]; $i <= $pages[1] || $last_page === 1; $i++) { if (count($urls) < $limit && $last_page === 0) { $urls[] = preg_replace('/\\[(.*)\\]/i', $i, $link); if ($i < $pages[1]) { continue; } } // var_dump($urls);echo '<br/>'; $last_page = 0; //采集列表内容 $mp->set_urls($urls); $contents = $mp->start(); foreach ($contents as $content) { $content = _prefilter($content); //debug // exit($content); //匹配内容 preg_match_all('/' . str_replace('/', '\\/', addslashes($list_rules)) . '/i', $content, $pregArr); $detail_urls = array(); foreach ($pregArr[1] as $detail_key => $detail_value) { $data = array(); if (count($detail_urls) < $limit) { $content_url = $base . $detail_value; $detail_urls[$content_url] = $content_url; if ($pregArr[1][$detail_key + 1] != '') { continue; }