Pthreads multi-thread data collection

Source: Internet
Author: User
: This article mainly introduces pthreads multi-threaded data collection. if you are interested in the PHP Tutorial, refer to it. In the past, multithreading with curl was not a real multithreading, but a simulated multithreading. now pthreads is used to implement real multithreading.

Download:

Windows:

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

For mac, unix, and linux:

Https://github.com/krakjoe/pthreads

Installation method:

Windows:

Decompress the pthreadvc2.dlland php_pthreads.dllfiles, put the vc2file to the same directory of php.exe, and put php_pthreads.dll to 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"

For mac, unix, and linux:

For details, refer to the banquet brother blog http://blog.s135.com/pthreads/

Call method:

Specific usage can also refer to the banquet brother blog http://blog.s135.com/pthreads/

Combined with the previous get_html, the class can also be implemented in this way.

 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 }

The above introduces pthreads multi-thread data collection, including the content, hope to be helpful to friends interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.