Pthreads multi-thread data collection, pthreads data collection _ PHP Tutorial

Source: Internet
Author: User
Pthreads multi-thread data collection and pthreads data collection. Pthreads multi-thread data collection, pthreads data collection used to use curl multithreading is not really multi-thread, but a simulated multi-thread. now pthreads is used to achieve true meaning of pthreads multi-thread data collection, pthreads data collection

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 }

In the past, the multi-thread that uses curl was not a real multi-thread, but a simulated multi-thread. now pthreads is used to implement the true meaning...

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.