Pthreads Multithreading data acquisition, PTHREADS data acquisition
Multithreading, formerly using Curl, is not really multi-threading, just a simulation of multi-threading, now using Pthreads to achieve the true meaning of multithreading.
Download:
Under Windows:
http://windows.php.net/downloads/pecl/releases/pthreads/0.0.45/
Under Mac, UNIX, Linux:
Https://github.com/krakjoe/pthreads
Installation method:
Under Windows:
Extract the PthreadVC2.dll and Php_pthreads.dll files, put the Vc2 file in the Php.exe sibling directory, and put the Php_pthreads.dll in the extension directory.
Modify the php.ini file to add Extension=php_pthreads.dll
Modify the Apache configuration file httpd.conf add LoadFile "Yourpath/php/pthreadvc2.dll"
Under Mac, UNIX, Linux:
For details, refer to the blog http://blog.s135.com/pthreads/of the feast brother
Call Mode:
The specific usage can also refer to the blog of the Feast brother Http://blog.s135.com/pthreads/
Combining the previous get_html can also be used to implement the class
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; 1 0 }11 Public function run () { if (!empty ($this->url)) { $this->data = $this->get_html ($this->url, $this->options); }16 }17 public function get_html ($url, $options = Array ()) {19 if (empty ($options)) { $options [curlopt_returntransfer] = true;21 $options [curlopt_timeout] = 5;22 }23 $ch = Curl_init ($url), Curl_setopt_array ($ch, $options); $html = curl_exec ($ch); 26 curl_close ($ch); if ($html = = = False) { false;29 }30 return $html; }32}
http://www.bkjia.com/PHPjc/1089436.html www.bkjia.com true http://www.bkjia.com/PHPjc/1089436.html techarticle pthreads Multithreading Data acquisition, Pthreads data acquisition previously using Curl multithreading is not really multi-threading, just a simulation of multi-threading, now using Pthreads to realize the true meaning ...