search
HomeBackend DevelopmentPHP Tutorialpthreads multi-threaded data collection_PHP tutorial
pthreads multi-threaded data collection_PHP tutorialJul 13, 2016 am 10:42 AM
curlpthreadsusedata collectionsimulationNowofthread

The multi-threading that used curl in the past was not a real multi-threading, it was just a simulated multi-threading. Now pthreads is used to achieve real multi-threading.

Download:

Under windows:

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

Under mac, unix, linux:

 https://github.com/krakjoe/pthreads

Under windows:

 Extract the pthreadVC2.dll and php_pthreads.dll files, put the vc2 file into the same directory as php.exe, and put php_pthreads.dll into the extension directory.

Modify the php.ini file and add extension=php_pthreads.dll

Modify the Apache configuration file httpd.conf and add LoadFile "yourpath/php/pthreadVC2.dll"

Under mac, unix, linux:

For details, please refer to Brother Yan’s blog http://blog.s135.com/pthreads/

Calling method:

For specific usage, you can also refer to Brother Yan’s blog http://blog.s135.com/pthreads/

Combined with the previous get_html, the class

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/667912.htmlTechArticleThe multi-threading that used curl in the past was not a real multi-threading, it was just a simulated multi-threading. Now we use pthreads To achieve true multi-threading. Download: under windows: http:...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
8核16线程是什么意思?8核16线程是什么意思?Feb 02, 2023 am 11:26 AM

8核是指CPU有8颗物理核心,16线程是指CPU最多同时可以有16个线程处理任务。核心数和线程数是电脑CPU的重要性能指标,CPU的核心数越高处理速度就越高;线程数越多越有利于同时运行多个程序,因为线程数等同于在某个瞬间CPU能同时并行处理的任务数。多线程可最大限度地实现宽发射、乱序的超标量处理,提高处理器运算部件的利用率,缓和由于数据相关或Cache未命中带来的访问内存延时。

什么是程序运行时指令流的最小单位什么是程序运行时指令流的最小单位Aug 23, 2022 pm 02:16 PM

“线程”是程序运行时指令流的最小单位。进程是指一个具有一定独立功能的程序,而线程是进程的一部分,描述指令流执行状态;线程是进程中的指令执行流的最小单位,是CPU调度的基本单位。一个线程是一个任务(一个程序段)的一次执行过程;线程不占有内存空间,它包括在进程的内存空间中。在同一个进程内,多个线程共享进程的资源;一个进程至少有一个线程。

Java错误:JavaFX线程卡顿错误,如何处理和避免Java错误:JavaFX线程卡顿错误,如何处理和避免Jun 24, 2023 pm 05:52 PM

在进行JavaFX应用程序开发的过程中,我们常常会遇到JavaFX线程卡顿错误。这种错误的严重程度不同,可能会对程序的稳定性和性能产生不利的影响。为了保证程序的正常运行,我们需要了解JavaFX线程卡顿错误的原因和解决方法,以及如何预防这种错误的发生。一、JavaFX线程卡顿错误的原因JavaFX是一个多线程的UI应用程序框架,它允许程序在后台线程中执行长时

go语言中协程与线程的区别是什么go语言中协程与线程的区别是什么Feb 02, 2023 pm 06:10 PM

区别:1、一个线程可以多个协程,一个进程也可以单独拥有多个协程;2、线程是同步机制,而协程则是异步;3、协程能保留上一次调用时的状态,线程不行;4、线程是抢占式,协程是非抢占式的;5、线程是被分割的CPU资源,协程是组织好的代码流程,协程需要线程来承载运行。

Java使用Thread类的stop()函数强制终止线程的执行Java使用Thread类的stop()函数强制终止线程的执行Jul 26, 2023 am 09:28 AM

Java使用Thread类的stop()函数强制终止线程的执行在Java多线程编程中,有时候我们需要强制终止一个正在执行的线程。Java提供了Thread类的stop()函数来实现线程的强制终止。本文将介绍stop()函数的用法,并提供代码示例来说明。在介绍stop()函数之前,我们先了解一下Thread类的几个常用方法:start():启动线程,使线程进入

Microsoft计划在Windows上的Outlook经典应用程序中引入AI驱动的CopilotMicrosoft计划在Windows上的Outlook经典应用程序中引入AI驱动的CopilotOct 19, 2023 pm 11:13 PM

Microsoft显然不会将其强大的人工智能支持的Copilot工具保留为新应用程序的独家功能。现在,该公司刚刚宣布计划在Windows上的Outlook经典应用程序中引入Copilot。正如其365路线图网站上发布的那样,预览将于明年&lt;&gt;月开始,直到&lt;&gt;月在当前频道的桌面上在全球范围内推出。Copilot是一种生产力工具,它使用大型语言模型(LLM)来帮助用户完成编写电子邮件、汇总文档和翻译语言等任务。它的主要功能之一是它能够总结电子邮件

我们如何在Java中实现一个计时器线程?我们如何在Java中实现一个计时器线程?Aug 30, 2023 pm 02:49 PM

Timer类安排任务在给定时间运行一次或重复。它还可以作为守护线程在后台运行。要将Timer与守护线程关联起来,需要使用一个带有布尔值的构造函数。计时器以固定延迟和固定速率安排任务。在固定延迟下,如果任何一个执行被系统GC延迟,则其他执行也会延迟,并且每次执行都会延迟对应于之前的执行。在固定速率下,如果任何执行被系统GC延迟,则连续发生2-3次执行以覆盖与第一次执行开始时间相对应的固定速率。Timer类提供了cancel()方法来取消计时器。当调用该方法时,定时器终止。Timer类仅执行实现Ti

线程的生命周期分几个阶段线程的生命周期分几个阶段Feb 21, 2023 pm 04:24 PM

5个阶段:1、新建,是刚使用new方法,new出来的线程;2、就绪,是调用的线程的start()方法后,这时候线程处于等待CPU分配资源阶段;3、运行,当就绪的线程被调度并获得CPU资源时,便进入运行状态;4、阻塞,在运行状态的时候,可能因为某些原因导致运行状态的线程变成了阻塞状态;5、销毁,线程正常执行完毕后或线程被提前强制性的终止或出现异常导致结束,那么线程就要被销毁。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use