1,pthreads扩展方案,结果耗损内存巨大不理想,最好少用
2,php自带curl:(满足场景要求,稳定)
function Mcurl($urls){
pthreed=curlmultiinit();foreach(urls as $key => $urlInfo) {
conn[key]=curl_init(
urlInfo[′url′]);curlsetopt(conn[
key],CURLOPTHTTPHEADER,array("Content−type:application/json;charset=utf−8",′Accept−Encoding:gzip′));curlsetopt(conn[
key],CURLOPTUSERAGENT,"eleme−openapi−php−sdk");curlsetopt(conn[
key],CURLOPTENCODING,"gzip");curlsetopt(conn[
key],CURLOPTCUSTOMREQUEST,′POST′);curlsetopt(conn[
key],CURLOPTPOSTFIELDS,jsonencode(urlInfo[‘data’]));
curl_setopt(
conn[key], CURLOPT_RETURNTRANSFER,1);
curl_setopt(
conn[key], CURLOPT_TIMEOUT,5);
curl_setopt(
conn[key], CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt(
conn[key], CURLOPT_SSL_VERIFYHOST, 0);
curl_multi_add_handle (
pthreed,conn[KaTeX parse error: Expected 'EOF', got '}' at position 11: key]); }̲ do {mrc = curl_multi_exec(
pthreed,active);} while (
mrc==CURLMCALLMULTIPERFORM);while(active and KaTeX parse error: Expected '}', got 'EOF' at end of input: …l_multi_select(pthreed) != -1) {
do {
mrc=curlmultiexec(pthreed, KaTeX parse error: Expected 'EOF', got '}' at position 9: active);}̲ while (mrc == CURLM_CALL_MULTI_PERFORM);
}
}
foreach ($urls as $key => $url) {
res[key]=curl_multi_getcontent(
conn[key]);
curl_close(
conn[key]);
}
return $res;
}