Download the PHP package calabashdoll/curl-future without Composer
On this page you can find all versions of the php package calabashdoll/curl-future. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download calabashdoll/curl-future
More information about calabashdoll/curl-future
Files in calabashdoll/curl-future
Download calabashdoll/curl-future
More information about calabashdoll/curl-future
Files in calabashdoll/curl-future
Vendor calabashdoll
Package curl-future
Short Description Parallel CURL Requests with PHP
License MIT
Package curl-future
Short Description Parallel CURL Requests with PHP
License MIT
Please rate this library. Is it a good library?
Informations about the package curl-future
CurlFuture: PHP Curl并行轮转请求库
multicurl系列方法是提高php请求后端http接口的一种途径。但是直接使用的话,存在几方面问题:
- 部分版本的curl扩展有bug,需要用特定的方式来调用(Rolling cURL: PHP并发最佳实践)
- 网上流传的CurlRolling库都只支持前面加入,最后一并执行这种使用模式。而最理想的是随时加入,需要的时候从里面取出所需的结果,且不需等待其他请求返回
- 为了提升效率,大部分库选择使用回调函数的方式来执行,对已有程序改造成本较高
为了解决这些问题,开发了CurlFuture库,实现了并行请求,先到先取,链式执行的特性。
应用场景
对于一些大型公司,PHP作为接口聚合层来使用,而接口通过HTTP协议给出。对于一些复杂的页面,可能需要请求几十个相互独立的接口, 如果使用并行模式,则可以极大的提升性能。
安装方法
引入入口php文件即可:include __DIR__.'/curl_future.php';
使用方法
并行请求的实例(async.php)
链式执行的示例(then.php)
和Model/Service结合的示例(model.php)
原理
在每次fetch的时候,开始事件循环。当所需http返回后,结束循环。继续执行php逻辑。
性能测试
请求本机接口200次,nginx默认页面,同步、异步与file_get_contents对比
/example/bench.php
curl_future sync:384 ms
file_get_contents:390 ms
curl_futhre async:68 ms
curl_future sync:624 ms
file_get_contents:460 ms
curl_futhre async:69 ms
curl_future sync:463 ms
file_get_contents:355 ms
curl_futhre async:70 ms
curl_future sync:447 ms
file_get_contents:409 ms
curl_futhre async:66 ms
同步方式没有file_get_contents稳定,但是异步批量方式性能提升很明显。
参考项目
All versions of curl-future with dependencies
PHP Build Version
Package Version
No informations.
The package calabashdoll/curl-future contains the following files
Loading the files please wait ....