I found a class online but didn't use the sample code. How can I use this class? {Code...} Please give me a sample code. I Want To Do multi-threaded post. I found a class online, but I didn't use the sample code,
How can I use this class?
$ 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 ', 'result'); 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 ;}
Please give me the sample code
I want to do multi-thread post
Reply content:
I found a class on the Internet, but I didn't use the sample code,
How can I use this class?
$ 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 ', 'result'); 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 ;}
Please give me the sample code
I want to do multi-thread post
$urls=['wwww.baidu.com','www.google.com','www.qq.com'];$post_data=['aa'=>'bb'];$resp=curl($urls,$post_data);print_r($resp);
First, this is just a function.
Second, how can I write it clearly in code comments,
/
Php curl multi-thread GET/POST
Email: szj1006@vip.qq.com/QQ: 690204663
Curl (array ('url? Get = data ', 'url'), array ('', 'Post _ data '));
*/
In use, if the class is used
Recommendation
-
Snoopy is not obtained through curl
-
[Requests for php] (http://requests.ryanmccue.info /)
Multi-threaded curl recommends this https://github.com/ares333/php-curlmulti
Multi-thread curl recommendation https://github.com/actors315/SmartCurl.git