PHP Curl multithreaded Operation code instance, CURL instance
How to use:
$urls = Array ("http://baidu.com", "http://21andy.com", "http://google.com"), $mp = new Multihttprequest ($urls); $MP- >start ();
/* * Curl Multithreading class * How to use: * ======================== $urls = Array ("http://baidu.com", "http://dzone.com", "http://google.com $MP = new Multihttprequest ($urls); $mp->start (); * ======================== */class multihttprequest {public $urls = array (); Public $curlopt _header = 1; Public $method = "GET"; function __construct ($urls = False) {$this->urls = $urls; } function Set_urls ($urls) {$this->urls = $urls; return $this; } function Is_return_header ($b) {$this->curlopt_header = $b; return $this; } function Set_method ($m) {$this->medthod = Strtoupper ($m); return $this; } function Start () {if (!is_array ($this->urls) or count ($this->urls) = = 0) {return false; } $curl = $text = Array (); $handle = Curl_multi_init (); foreach ($this->urls as $k = + $v) {$curl [$k] = $this->add_handle ($handle, $v); } $this->exec_handle ($handle); foreach ($this->urls as $k = + $v) {curL_multi_getcontent ($curl [$k]); echo $curl [$k]. " \ n "; $text [$k] = Curl_multi_getcontent ($curl [$k]); Echo $text [$k], "\ n"; Curl_multi_remove_handle ($handle, $curl [$k]); } curl_multi_close ($handle); } Private Function Add_handle ($handle, $url) {$curl = Curl_init (); curl_setopt ($curl, Curlopt_url, $url); curl_setopt ($curl, Curlopt_header, $this->curlopt_header); curl_setopt ($curl, Curlopt_returntransfer, 1); Curl_multi_add_handle ($handle, $curl); return $curl; } Private Function Exec_handle ($handle) {$flag = null; do {curl_multi_exec ($handle, $flag); } while ($flag > 0); }}
http://www.bkjia.com/PHPjc/998809.html www.bkjia.com true http://www.bkjia.com/PHPjc/998809.html techarticle PHP Curl Multithreaded Operation code instance, CURL instance use method: $urls = Array ("http://baidu.com", "http://21andy.com", "http://google.com"); $mp = New Multihttprequest ($urls); $MP-...