You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind.
4
+
`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.
5
+
6
+
See the `Worker` and `Task` interfaces in [`amphp/parallel`](https://github.com/amphp/parallel) for a more flexible and customizable API for running tasks in parallel.
Documentation can be found on [amphp.org](https://amphp.org/parallel-functions/) as well as in the [`./docs`](./docs) directory.
21
+
- PHP 8.1+
21
22
22
23
## Example
23
24
24
25
```php
25
26
<?php
26
27
27
28
use function Amp\ParallelFunctions\parallelMap;
28
-
use function Amp\Promise\wait;
29
29
30
-
$responses = wait(parallelMap([
30
+
$responses = parallelMap([
31
31
'https://google.com/',
32
32
'https://github.com/',
33
33
'https://stackoverflow.com/',
34
34
], function ($url) {
35
35
return file_get_contents($url);
36
-
}));
36
+
});
37
37
```
38
38
39
+
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).
40
+
41
+
We recommend performing HTTP requests using [`amphp/http-client`](https://github.com/amphp/http-client).
42
+
43
+
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.
44
+
39
45
Further examples can be found in the [`./examples`](examples) directory.
40
46
41
47
## Versioning
@@ -44,7 +50,7 @@ Further examples can be found in the [`./examples`](examples) directory.
44
50
45
51
## Security
46
52
47
-
If you discover any security related issues, please email [`[email protected]`](mailto:[email protected])instead of using the issue tracker.
53
+
If you discover any security related issues, please use the private security issue reporter instead of using the public issue tracker.
0 commit comments