AmpPHP 非阻塞并发框架
Amp 是一个 PHP 非阻塞并发框架,它提供了一个事件循环,promise 和 stream 作为异步编程的基础。与生成器结合使用的 promise 用于构建协程,它允许像同步代码一样编写异步代码,而不需要任何回调。
demo:
<?php use Amp\Artax\Response; use Amp\Loop; require __DIR__ . '/../vendor/autoload.php'; Loop::run(function () { $uris = [ "https://google.com/", "https://github.com/", "https://stackoverflow.com/", ]; $client = new Amp\Artax\DefaultClient; $client->setOption(Amp\Artax\Client::OP_DISCARD_BODY, true); try { foreach ($uris as $uri) { $promises[$uri] = $client->request($uri); } $responses = yield $promises; foreach ($responses as $uri => $response) { print $uri . " - " . $response->getStatus() . $response->getReason() . PHP_EOL; } } catch (Amp\Artax\HttpException $error) { // If something goes wrong Amp will throw the exception where the promise was yielded. // The Client::request() method itself will never throw directly, but returns a promise. print $error->getMessage() . PHP_EOL; } });
评论
swPromisePHP纯异步非阻塞框架
swPromise,基于swoole的PHPpromise框架一个业务请求可能会串行的请求多个接口A->B->C,此时如果接口B的响应时间较慢(关键性业务,需要有预先准备好的超时等待时间)
swPromisePHP纯异步非阻塞框架
0
PHP AMPPHP MVC框架
欢迎使用PHPMVC开源框架-AMP AMP-优雅精致的WEB应用开发MVC框架。为什么选择AMP?01)快速:框架核心文件总大小10余KB,0.0001毫秒迅速载入启动。02)高效:安全高效性能、优
PHP AMPPHP MVC框架
0
Strato NCache非阻塞式缓存框架
缓存是服务器程序中经常用到的技术,使用缓存可以大大降低服务器的压力。目前常见的缓存工具都很好地解决了生命周期、存储、命中率等关键算法,但是绝大多数的缓存框架对于数据更新都是阻塞式的,即当缓存过期时会等
Strato NCache非阻塞式缓存框架
0