国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

pthreads多線程數據采集

2019-11-14 13:18:41
字體:
來源:轉載
供稿:網友

以前使用curl的多線程并不是真正的多線程,只是一種模擬的多線程,現在使用pthreads來實現真正意義上的多線程。

下載:

  windows下:

    http://windows.php.net/downloads/pecl/releases/pthreads/0.0.45/

  mac、unix、linux下:

    https://github.com/krakjoe/pthreads

安裝方式:

  windows下:

    解壓得到pthreadVC2.dll和php_pthreads.dll文件,把vc2文件放到php.exe同級目錄,把php_pthreads.dll放到擴展目錄下。

    修改php.ini文件 添加extension=php_pthreads.dll

    修改Apache配置文件httpd.conf 添加LoadFile "yourpath/php/pthreadVC2.dll"

  mac、unix、linux下:

    具體可參考宴哥的博客http://blog.s135.com/pthreads/

調用方式:

  具體的用法也可以參考宴哥的博客http://blog.s135.com/pthreads/

  結合以前的get_html也可以這樣來實現類

復制代碼
 1 class threads extends Thread 2 { 3     public $url = ''; 4     public $options = array(); 5     public $data; 6  7     public function __construct($url, $options = array()){ 8         $this->url = $url; 9         $this->options = $options;10     }11 12     public function run(){13         if(!empty($this->url)){14             $this->data = $this->get_html($this->url, $this->options);15         }16     }17 18     public function get_html($url,$options = array()){19         if(empty($options)){20             $options[CURLOPT_RETURNTRANSFER] = true;21             $options[CURLOPT_TIMEOUT] = 5;22         }23         $ch = curl_init($url);24         curl_setopt_array($ch,$options);25         $html = curl_exec($ch);26         curl_close($ch);27         if($html === false){28             return false;29         }30         return $html;31     }32 }
復制代碼

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新野县| 嘉善县| 皮山县| 荔浦县| 教育| 柞水县| 错那县| 濮阳县| 河池市| 阿克陶县| 嘉义县| 滦南县| 时尚| 阜康市| 灵石县| 武隆县| 年辖:市辖区| 清新县| 罗城| 南宁市| 东兰县| 弥渡县| 嘉兴市| 涪陵区| 天峨县| 阿勒泰市| 格尔木市| 上栗县| 乐平市| 铅山县| 田阳县| 噶尔县| 资兴市| 沭阳县| 哈尔滨市| 甘洛县| 通辽市| 常州市| 芜湖市| 沧源| 太谷县|