以前使用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也可以这样来实现类

 class threads extends Thread
{
public $url = '';
public $options = array();
public $data; public function __construct($url, $options = array()){
$this->url = $url;
$this->options = $options;
} public function run(){
if(!empty($this->url)){
$this->data = $this->get_html($this->url, $this->options);
}
} public function get_html($url,$options = array()){
if(empty($options)){
$options[CURLOPT_RETURNTRANSFER] = true;
$options[CURLOPT_TIMEOUT] = 5;
}
$ch = curl_init($url);
curl_setopt_array($ch,$options);
$html = curl_exec($ch);
curl_close($ch);
if($html === false){
return false;
}
return $html;
}
}

pthreads多线程数据采集的更多相关文章

  1. 如何让您的php也支持pthreads多线程

    我们常常会碰到这样一种情况,开发环境在windows下开发,而生产环境确是linux.windows下能正常运行,上传到linux后却无法好好地玩耍了.然后开始了一轮尼玛式的疯狂的查找原因,最后发现是 ...

  2. PHP安装pthreads多线程扩展教程[windows篇]

    from:http://blog.csdn.net/aoyoo111/article/details/19020161 一.判断PHP是ts还是nts版 通过phpinfo(); 查看其中的 Thre ...

  3. windows下xampp安装PHP的pthreads多线程扩展

    我的运行环境: 系统:windows10 ,64位 PHP:5.6.8 TS,VC11 ,32位 Apache: 2.0 我安装的是xampp集成环境 pthreads的windows扩展文件下载地址 ...

  4. PHP 之pthreads多线程模块在windows下的安装

    一.查看phpinfo 二.下载pthreads扩展 下载地址:http://windows.php.net/downloads/pecl/releases/pthreads/ 三.复制文件 复制ph ...

  5. Windows环境下PHP安装pthreads多线程扩展

    一.判断PHP是ts还是nts版 通过phpinfo(); 查看其中的 Thread Safety 项,这个项目就是查看是否是线程安全,如果是:enabled,一般来说应该是ts版,否则是nts版. ...

  6. php pthreads 多线程扩展的使用:一个较为稳定例子。

    今天研究了worker stackable的配合方法,写了两种形式,虽然能工作,但是都会出现内存不听增长的问题: 于是把第一个方法的代码邮件给了作者,到现在他没有回复我. 我最后放弃两者配合的方式,直 ...

  7. 本人第一个开源代码,NETSpider 网络蜘蛛采集工具

    NETSpider网站数据采集软件是一款基于.Net平台的开源软件.软件部分功能是基本Soukey软件进行开发的.这个版本采用VS2010+.NET3.5进行开发的.NETSpider采摘当前提供的主 ...

  8. python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客

    python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客 undefined Python多线程抓取代理服务器 | Linux运维笔记 undefined java如 ...

  9. PHP-FPM进程池探秘

    PHP 支持多进程而不支持多线程:PHP-FPM 在进程池中运行多个子进程并发处理所有连接请求.通过 ps 查看PHP-FPM进程池(pm.start_servers = 2)状态如下: root@d ...

随机推荐

  1. Need help with design ReadOnlyListBase (Insert, Update, Delete from ReadOnlyListBase)

    原文地址:http://forums.lhotka.net/forums/p/3166/21214.aspx My task is: For select client, I have a modal ...

  2. nyoj 92 图像有用区域

    点击打开链接 图像有用区域 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 "ACKing"同学以前做一个图像处理的项目时,遇到了一个问题,他需要摘取 ...

  3. SQL行转列汇总

    PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P ...

  4. 使用Semaphore控制并发访问

    Semaphore,信号量. 用在多线程环境下对共享资源访问的一种协调机制. 当一个线程想要访问共享的资源时,这个线程需要获取Semaphore,如果Semaphore内部计数器的值大于0,Semap ...

  5. (转)adb shell am 的用法

    原文地址:http://blog.csdn.net/fulinwsuafcie/article/details/8092459   adb shell am 的功能 adb shell am 使用此命 ...

  6. IOS开发-文件管理(二)

    IOS开发-文件管理(二) 五.Plist文件 String方式添加               NSString *path = [NSHomeDirectory( )  stringByAppen ...

  7. Oracle数据库(1)

    Oracle基本数据类型:Oracle的基本呢数据类型按类型分为:字符串类型,数据类型,日期类型,LOB类型等.1.字符串类型:①char:定长字符串,最多存储2k字节,在不指定char长度的情况下, ...

  8. 【LeetCode】21. Merge Two Sorted Lists

    题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...

  9. 支撑5亿用户、1.5亿活跃用户的Twitter最新架构详解及相关实现

    如果你对项目管理.系统架构有兴趣,请加微信订阅号"softjg",加入这个PM.架构师的大家庭 摘要:Twitter出道之初只是个奋斗在RoR上的小站点,而如今已拥有1.5亿的活跃 ...

  10. .net Url重写

    详细说明及下载dll源码路径: http://msdn.microsoft.com/zh-cn/library/ms972974.aspx 顺带上本人写的一个小例子:http://files.cnbl ...