├── .DS_Store ├── content.sql ├── images └── .DS_Store ├── libs └── class_curl_multi.php └── splider.php /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyhiving/MultiHttpRequest/fe20c9376a5ff02948cfe0a29983b1f15fe69e8d/.DS_Store -------------------------------------------------------------------------------- /content.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 3.5.0 3 | -- http://www.phpmyadmin.net 4 | -- 5 | -- 主机: localhost 6 | -- 生成日期: 2012 年 05 月 22 日 10:48 7 | -- 服务器版本: 5.1.44 8 | -- PHP 版本: 5.3.1 9 | 10 | SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | 14 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 15 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 16 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 17 | /*!40101 SET NAMES utf8 */; 18 | 19 | -- 20 | -- 数据库: `test` 21 | -- 22 | 23 | -- -------------------------------------------------------- 24 | 25 | -- 26 | -- 表的结构 `content` 27 | -- 28 | 29 | CREATE TABLE IF NOT EXISTS `content` ( 30 | `id` int(9) NOT NULL AUTO_INCREMENT, 31 | `meta_title` varchar(255) CHARACTER SET latin1 NOT NULL, 32 | `meta_keywords` varchar(255) CHARACTER SET latin1 NOT NULL, 33 | `meta_description` varchar(255) CHARACTER SET latin1 NOT NULL, 34 | `product_name` varchar(255) CHARACTER SET latin1 NOT NULL, 35 | `product_image` varchar(255) CHARACTER SET latin1 NOT NULL, 36 | `product_price` varchar(255) CHARACTER SET latin1 NOT NULL, 37 | `product_description` text CHARACTER SET latin1 NOT NULL, 38 | `product_url` varchar(255) CHARACTER SET latin1 NOT NULL, 39 | UNIQUE KEY `id` (`id`) 40 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; 41 | 42 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 43 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 44 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 45 | -------------------------------------------------------------------------------- /images/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lyhiving/MultiHttpRequest/fe20c9376a5ff02948cfe0a29983b1f15fe69e8d/images/.DS_Store -------------------------------------------------------------------------------- /libs/class_curl_multi.php: -------------------------------------------------------------------------------- 1 | start(); 9 | 10 | * ======================== 11 | */ 12 | class MultiHttpRequest { 13 | public $urls = array(); 14 | public $curlopt_header = 0; 15 | public $method = "GET"; 16 | 17 | function __construct($urls = false) { 18 | $this->urls = $urls; 19 | } 20 | 21 | function set_urls($urls) { 22 | $this->urls = $urls; 23 | return $this; 24 | } 25 | 26 | function is_return_header($b) { 27 | $this->curlopt_header = $b; 28 | return $this; 29 | } 30 | 31 | function set_method($m) { 32 | $this->medthod = strtoupper($m); 33 | return $this; 34 | } 35 | 36 | function start() { 37 | if(!is_array($this->urls) or count($this->urls) == 0){ 38 | return false; 39 | } 40 | $curl = $text = array(); 41 | $handle = curl_multi_init(); 42 | foreach($this->urls as $k=>$v){ 43 | $curl[$k] = $this->add_handle($handle, $v); 44 | } 45 | 46 | $this->exec_handle($handle); 47 | foreach($this->urls as $k=>$v){ 48 | //curl_multi_getcontent($curl[$k]); 49 | //echo $curl[$k]."\n"; 50 | $text[$k] = curl_multi_getcontent($curl[$k]); 51 | //echo $text[$k], "\n\n"; 52 | curl_multi_remove_handle($handle, $curl[$k]); 53 | } 54 | curl_multi_close($handle); 55 | 56 | return $text; 57 | } 58 | 59 | private function add_handle($handle, $url) { 60 | $curl = curl_init(); 61 | curl_setopt($curl, CURLOPT_URL, $url); 62 | 63 | curl_setopt($curl, CURLOPT_HEADER, $this->curlopt_header); 64 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 65 | curl_multi_add_handle($handle, $curl); 66 | return $curl; 67 | } 68 | 69 | private function exec_handle($handle) { 70 | $flag = null; 71 | do { 72 | curl_multi_exec($handle, $flag); 73 | } while ($flag > 0); 74 | } 75 | 76 | public function get_content($url){ 77 | $ch = curl_init(); 78 | curl_setopt ($ch, CURLOPT_URL, $url); 79 | curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 80 | curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10); 81 | return curl_exec($ch); 82 | } 83 | } -------------------------------------------------------------------------------- /splider.php: -------------------------------------------------------------------------------- 1 | .*'; 34 | 35 | //内容页面信息字段表达式 36 | $detail_rules = array( 37 | 'meta_title'=>'