PHP CURL Multithreading Get/post class

Source: Internet
Author: User

PHP CURL Multithreading Get/post class2015-01-01 Category: Technical articles read (623) Comments (0)

If there is a need to correct or more efficient suggestions, welcome to share ~\ (≧▽≦) in Oschina/~

http://www.oschina.net/code/snippet_1475115_44902

<?PHP/**************************************************************** PHP CURLMultithreadingGet/post email:[email protected]/qq:690204663 Powered by XiaosangCurl(Array (' Url?get=data ', ' url '), Array (' ', ' post_data ')); *****************************************************************/ function Curl($urls,$post) {$queue= Curl_multi_init();$map=Array(); Foreach ($urlsAs$key=$url) {$ch=Curl_init();curl_setopt($ch,Curlopt_url,$url);curl_setopt($ch,Curlopt_timeout, 30);curl_setopt($ch,Curlopt_returntransfer, 1);curl_setopt($ch,Curlopt_postfields,$post[$key]);curl_setopt($ch,Curlopt_header, 0);curl_setopt($ch,Curlopt_nosignal, True);Curl_multi_add_handle($queue,$ch);$map[(String)$ch] =$url; }$responses=Array(); Do { While (($code=Curl_multi_exec($queue,$active)) ==Curlm_call_multi_perform) ; If ($code!=Curlm_ok) { Break; } While ($done=Curl_multi_info_read($queue)) {$error=Curl_error($done[' Handle ']);$results=Curl_multi_getcontent($done[' Handle ']);$responses[$map[(String)$done[' Handle ']]] =Compact(' Error ', ' Results ');Curl_multi_remove_handle($queue,$done[' Handle ']);Curl_close($done[' Handle ']); } If  ( $active > 0)  { Curl_multi_select ( $queue , 0.5); } } while $active  Curl_multi_close  $queue return $responses ;               /span>                

PHP CURL multithreaded Get/post class

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.