{"id":33990234,"url":"https://github.com/phanxipang/peak","last_synced_at":"2026-01-11T11:01:23.374Z","repository":{"id":152221832,"uuid":"620376624","full_name":"phanxipang/peak","owner":"phanxipang","description":"Send multiple requests concurrently using any PSR-18 client implementations","archived":false,"fork":false,"pushed_at":"2023-11-05T13:21:41.000Z","size":72,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-14T18:05:28.551Z","etag":null,"topics":["async","concurrent","http","parralel","psr-18"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phanxipang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-03-28T15:01:04.000Z","updated_at":"2024-03-27T07:14:03.000Z","dependencies_parsed_at":"2023-09-23T05:52:14.216Z","dependency_job_id":null,"html_url":"https://github.com/phanxipang/peak","commit_stats":null,"previous_names":["phanxipang/concurrent","jenky/atlas-pool"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/phanxipang/peak","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanxipang%2Fpeak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanxipang%2Fpeak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanxipang%2Fpeak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanxipang%2Fpeak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phanxipang","download_url":"https://codeload.github.com/phanxipang/peak/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phanxipang%2Fpeak/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28301264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T08:21:30.231Z","status":"ssl_error","status_checked_at":"2026-01-11T08:21:26.882Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","concurrent","http","parralel","psr-18"],"created_at":"2025-12-13T06:04:32.442Z","updated_at":"2026-01-11T11:01:23.356Z","avatar_url":"https://github.com/phanxipang.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Peak\n\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Github Actions][ico-gh-actions]][link-gh-actions]\n[![Codecov][ico-codecov]][link-codecov]\n[![Total Downloads][ico-downloads]][link-downloads]\n[![Software License][ico-license]](LICENSE.md)\n\nA simple and efficient solution for concurrently sending HTTP requests using PSR-18 client implementations.\n\nPeak is a library that enables concurrent request sending using a request pool. It leverages the event loop of [AMPHP](https://github.com/amphp), [ReactPHP](https://github.com/reactphp) or [PSL](https://github.com/azjezz/psl) to handle and manage the requests concurrently.\n\n## Requirements\n\n- PHP 8.1 or higher.\n- A package that supports non-block I/O using Fibers under the hood (now refer as **driver**).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require fansipan/peak\n```\n\nAdditionally, depending on your choice of driver, these packages may also need to be installed.\n\n### AMPHP\n\n```bash\ncomposer require amphp/pipeline\n```\n\n### PSL\n\n```bash\ncomposer require azjezz/psl\n```\n\n### ReactPHP\n\n```bash\ncomposer require clue/mq-react react/async\n```\n\n## Usage\n\n### Create Request Pool\n\nTypical applications would use the `PoolFactory` class to create a pool.\n\n```php\nuse Fansipan\\Peak\\PoolFactory;\n\n/** @var \\Psr\\Http\\Client\\ClientInterface $client */\n$pool = PoolFactory::createForClient($client);\n```\n\nIt will attempt to create async version of the client using `AsyncClientFactory`. The supported clients are [Guzzle](https://github.com/guzzle/guzzle) and [Symfony HTTPClient](https://github.com/symfony/http-client) ([`Psr18Client`](https://symfony.com/doc/current/http_client.html#psr-18-and-psr-17)).\n\n\u003e You can use any PSR-18 client implementations with ReactPHP driver. If an unsupported client is used, it will be replaced with the [`Browser`](https://github.com/reactphp/http#browser) HTTP client (require `react/http` installed).\n\nThe `Fansipan\\Peak\\PoolFactory` provides a configured request pool based on the installed packages, which is suitable for most cases. However, if desired, you can specify a particular implementation if it is available on your platform and/or in your application.\n\nFirst, you need to create your desired driver:\n\n```php\nuse Fansipan\\Peak\\Concurrency\\AmpDeferred;\nuse Fansipan\\Peak\\Concurrency\\PslDeferred;\nuse Fansipan\\Peak\\Concurrency\\ReactDeferred;\n\n// AMPHP\n$defer = new AmpDeferred();\n\n// PSL\n$defer = new PslDeferred();\n\n// ReactPHP\n$defer = new ReactDeferred();\n```\n\nThen create an asynchronous client, which is essentially a decorator for the PSR-18 client:\n\n```php\nuse Fansipan\\Peak\\Client\\GuzzleClient;\nuse Fansipan\\Peak\\Client\\SymfonyClient;\nuse Fansipan\\Peak\\ClientPool;\n\n// Guzzle\n\n$asyncClient = new GuzzleClient($defer);\n// or using existing Guzzle client\n/** @var \\GuzzleHttp\\ClientInterface $client */\n$asyncClient = new GuzzleClient($defer, $client);\n\n// Symfony HTTP Client\n\n$asyncClient = new SymfonyClient($defer);\n// or using existing Symfony client\n/** @var \\Symfony\\Contracts\\HttpClient\\HttpClientInterface $client */\n$asyncClient = new SymfonyClient($defer, $client);\n\n\n$pool = new ClientPool($asyncClient);\n```\n\n### Sending Requests\n\nThe `send` method accepts an iterator of PSR-7 requests or closures/invokable class which receive an `Psr\\Http\\Client\\ClientInterface` instance.\n\n```php\nuse Psr\\Http\\Client\\ClientInterface;\nuse Psr\\Http\\Message\\RequestInterface;\nuse Psr\\Http\\Message\\ResponseInterface;\n\n// Using array\n$responses = $pool-\u003esend([\n    $psr7Request,\n    fn (ClientInterface $client): ResponseInterface =\u003e $client-\u003esendRequest($psr7Request),\n]);\n\nvar_dump($responses[0]);\nvar_dump($responses[1]);\n\n// Using generator when you have an indeterminate amount of requests you wish to send\n$requests = static function (int $total) {\n    for ($i = 0; $i \u003c $total; $i++) {\n        yield $psr7Request;\n    }\n}\n$responses = $pool-\u003esend($requests(100));\n```\n\n### Retrieving Responses\n\nAs you can see from the example above, each response instance can be accessed using an index. However, the response order is not guaranteed. If you wish, you can assign names to the requests to easily track the specific requests that have been sent. This allows you to access the corresponding responses by their assigned names.\n\n```php\nuse Psr\\Http\\Client\\ClientInterface;\nuse Psr\\Http\\Message\\RequestInterface;\nuse Psr\\Http\\Message\\ResponseInterface;\n\n$responses = $pool-\u003esend([\n    'first' =\u003e $psr7Request,\n    'second' =\u003e fn (ClientInterface $client): ResponseInterface =\u003e $client-\u003esendRequest($psr7Request),\n]);\n\n// Or using generator\n\n$requests = function (): \\Generator {\n    yield 'first' =\u003e $psr7Request;\n    yield 'second' =\u003e fn (ClientInterface $client): ResponseInterface =\u003e $client-\u003esendRequest($psr7Request);\n};\n\n$responses = $pool-\u003esend($requests());\n\nvar_dump($responses['first']);\nvar_dump($responses['second']);\n```\n\n### Concurrency Limit\n\nSending an excessive number of requests may either take up all resources on your side or it may even get you banned by the remote side if it sees an unreasonable number of requests from your side.\n\nAs a consequence, it's usually recommended to limit concurrency on the sending side to a reasonable value. It's common to use a rather small limit, as doing more than a dozen of things at once may easily overwhelm the receiving side.\n\nYou can use `concurrent` method to set the maximum number of requests to send concurrently. The default value is `25`.\n\n```php\n$response = $pool\n    -\u003econcurrent(10) // Process up to 10 requests concurrently\n    -\u003esend($requests);\n```\n\nAdditional requests that exceed the concurrency limit will automatically be enqueued until one of the pending requests completes.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email contact@lynh.me instead of using the issue tracker.\n\n## Credits\n\n- [Lynh](https://github.com/jenky)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/fansipan/peak.svg?style=for-the-badge\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=for-the-badge\n[ico-gh-actions]: https://img.shields.io/github/actions/workflow/status/phanxipang/peak/testing.yml?branch=main\u0026label=actions\u0026logo=github\u0026style=for-the-badge\n[ico-codecov]: https://img.shields.io/codecov/c/github/phanxipang/peak?logo=codecov\u0026style=for-the-badge\n[ico-downloads]: https://img.shields.io/packagist/dt/fansipan/peak.svg?style=for-the-badge\n\n[link-packagist]: https://packagist.org/packages/fansipan/peak\n[link-gh-actions]: https://github.com/phanxipang/peak\n[link-codecov]: https://codecov.io/gh/phanxipang/peak\n[link-downloads]: https://packagist.org/packages/fansipan/peak\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphanxipang%2Fpeak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphanxipang%2Fpeak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphanxipang%2Fpeak/lists"}