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...