v4.6.5没有向后不兼容的变化,主要对原生curlhook做了一些增强,支持curlmulti,在使用原生curlhook的前提下支持原生curlmulti它就是编译Swoole扩展时开启--enable-swoole-curl选项。可以使用如下代码进行测试://设置URL和相应的选项curl_setopt($ch1,CURLOPT_URL,"http://www.baidu.com/");curl_setopt($ch1,CURLOPT_HEADER,0);curl_setopt($ch1,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch2,CURLOPT_URL,"http://www.gov.cn/");curl_setopt($ch2,CURLOPT_HEADER,0);curl_setopt($ch2,CURLOPT_RETURNTRANSFER,1);$mh=curl_multi_init();curl_multi_add_handle($mh,$ch1);curl_multi_add_handle($mh,$ch2);$active=null;//执行批处理do{$mrc=curl_multi_exec($mh,$active);}while($mrc==CURLM_CALL_MULTI_PERFORM);while($active&&$mrc==CURLM_OK){$n=curl_multi_select($mh);if($n!=-1){do{$mrc=curl_multi_exec($mh,$active);}while($mrc==CURLM_CALL_MULTI_PERFORM);}}$info1=curl_multi_info_read($mh);$info2=curl_multi_info_read($mh);$info3=curl_multi_info_read($mh);断言($info1['msg']===CURLMSG_DONE);断言($info2['msg']===CURLMSG_DONE);断言($info3===false);assert(strpos(curl_multi_getcontent($ch1),'baidu.com')!==false);assert(strpos(curl_multi_getcontent($ch2),'中央人民政府门户网站')!==false);curl_multi_remove_handle($mh,$ch1);curl_multi_remove_handle($mh,$ch2);curl_multi_close($mh);});支持curlmulti之后,也间接支持Guzzle,不用改任何代码,准备支持包括__DIR__。'/vendor/autoload.php';使用Swoole\Coroutine\Barrier;使用Swoole\Runtime;使用GuzzleHttp\Client;使用GuzzleHttp\Promise;使用函数Swoole\Coroutine\run;使用函数Swoole\Coroutine\go;Runtime::enableCoroutine(SWOOLE_HOOK_NATIVE_CURL);constN=4;run(function(){$barrier=Barrier::make();$result=[];go(function()use($barrier,&$result){$client=newClient();$promises=['baidu'=>$client->getAsync('http://www.baidu.com/'),'qq'=>$client->getAsync('https://www.qq.com/'),'gov'=>$client->getAsync('http://www.gov.cn/')];$responses=Promise\Utils::unwrap($promises);断言(strpos($responses['baidu']->getBody(),'百度')!==false);assert(strpos(iconv('gbk','utf-8',$responses['qq']->getBody(),'腾讯')!==false);assert(strpos($responses['gov']->getBody(),'中华人民共和国')!==false);$result['task_1']='确定';});go(function()use($barrier,&$result){$client=newClient(['base_uri'=>'http://httpbin.org/']);$n=N;$data=$promises=[];while($n--){$key='req_'.$n;$data[$key]=uniqid('swoole_test');$promises[$key]=$client->getAsync('/base64/'.base64_encode($data[$key]));}$responses=Promise\Utils::unwrap($promises);$n=N;while($n--){$key='req_'.$n;assert($responses[$key]->getBody()===$data[$key]);}$result['task_2']='OK';});屏障::等待($屏障);assert($result['task_1']==='OK');assert($result['task_2']==='OK');回声“完成”。PHP_EOL;});还添加了一些Guzzle单元测试,以允许使用数组在使用HTTP/2的响应中设置标头。从v4.6.0开始,Swoole\Http\Response支持重复设置相同的$keyHTTPHeader,$value支持多种类型,比如array,object,int,float,底层会进行toString转换,会去掉最后的空格和换行符。但是,不支持HTTP/2。有关详细信息,请参阅问题#4133。这个版本也支持:$http=newSwoole\Http\Server('127.0.0.1',9501);$http->set(['open_http2_protocol'=>true]);$http->on('request',function($request,$response){$response->header('测试值',["a\r\n",'d5678',"e\n",null,5678,3.1415926,]);$response->end("
