Pthreads Multi-threaded data acquisition, pthreads data Acquisition _php Tutorial

Source: Internet
Author: User

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

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