parallel-functions
AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind.
amphp/parallel-functions
provides a utility function which wraps a callable into another callable which will execute on another process or thread. All data within the callable object or closure must be serializable.
See the Worker
and Task
interfaces in amphp/parallel
for a more flexible and customizable API for running tasks in parallel.
Installation
This package can be installed as a Composer dependency.
composer require amphp/parallel-functions
Requirements
PHP 8.1+Example
<?php use function AmpParallelFunctionsparallelMap; $responses = parallelMap([ 'https://google.com/', 'https://github.com/', 'https://stackoverflow.com/', ], function ($url) { return file_get_contents($url); });
Note that file_get_contents()
is being used here as an example blocking function (that is, a function which halts the process while awaiting I/O).
We recommend performing HTTP requests using amphp/http-client
.
The best functions to parallelize are those which perform many CPU-intensive calcuations or blocking functions which would be difficult or time-consuming to implement in a non-blocking way.
Further examples can be found in the ./examples
directory.
Versioning
amphp/parallel-functions
follows the semver semantic versioning specification like all other amphp
packages.
Security
If you discover any security related issues, please use the private security issue reporter instead of using the public issue tracker.
License
The MIT License (MIT). Please see LICENSE
for more information.
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。