1
0
mirror of https://github.com/danog/parallel.git synced 2024-11-26 12:24:40 +01:00
Go to file
Aaron Piotrowski 09ab72333b
Increase test timeout
Parallel threads only check for kills every 250 ms, so this can fail.
2020-02-10 17:40:52 -06:00
docs Revert #91 (#94) 2020-02-04 13:36:21 -06:00
examples Add support for krakjoe/parallel 2019-02-14 00:34:45 -06:00
lib Serialize exception trace arguments in child processes and threads 2020-02-10 17:30:09 -06:00
test Increase test timeout 2020-02-10 17:40:52 -06:00
travis Add support for krakjoe/parallel 2019-02-14 00:34:45 -06:00
.gitattributes Ignore the travis directory on export 2018-12-27 23:07:47 +01:00
.gitignore Ignore docs/Gemfile.lock 2019-11-03 15:11:37 +01:00
.gitmodules Add docs submodule 2017-12-08 17:53:20 -06:00
.php_cs.dist Fix code style 2018-10-07 09:50:45 -05:00
.travis.yml Update travis build 2020-02-10 17:30:50 -06:00
.valgrindrc Add helpful defaults for Valgrind 2015-08-27 12:33:19 -05:00
appveyor.yml Adjust AppVeyor to PHP 7.3 2019-01-09 22:31:46 +01:00
composer.json Serialize exception trace arguments in child processes and threads 2020-02-10 17:30:09 -06:00
LICENSE Update readme and license 2017-11-29 18:27:30 -06:00
Makefile Apply Amp's code style 2017-05-18 09:51:31 +02:00
phpdoc.dist.xml Port to Amp 2016-08-18 11:04:48 -05:00
phpunit.xml.dist Upgrade to PHPUnit 7 or 8 2019-08-27 12:17:41 -05:00
README.md Improve documentation 2018-11-04 10:17:19 -06:00
Vagrantfile Update vagrant box for PHP 7 2016-01-23 10:50:56 -06:00

parallel

Build Status Code Coverage Release License

amphp/parallel provides true parallel processing for PHP using multiple processes or native threads, without blocking and no extensions required.

To be as flexible as possible, this library comes with a collection of non-blocking concurrency tools that can be used independently as needed, as well as an "opinionated" worker API that allows you to assign units of work to a pool of worker threads or processes.

Installation

This package can be installed as a Composer dependency.

composer require amphp/parallel

Usage

The basic usage of this library is to submit blocking tasks to be executed by a worker pool in order to avoid blocking the main event loop.

<?php

require __DIR__ . '/../vendor/autoload.php';

use Amp\Parallel\Worker;
use Amp\Promise;

$urls = [
    'https://secure.php.net',
    'https://amphp.org',
    'https://github.com',
];

$promises = [];
foreach ($urls as $url) {
    $promises[$url] = Worker\enqueueCallable('file_get_contents', $url);
}

$responses = Promise\wait(Promise\all($promises));

foreach ($responses as $url => $response) {
    \printf("Read %d bytes from %s\n", \strlen($response), $url);
}

file_get_contents is just used as an example for a blocking function here. If you just want to fetch multiple HTTP resources concurrently, it's better to use Artax, our non-blocking HTTP client.

The functions you call must be predefined or autoloadable by Composer so they also exist in the worker processes. Instead of simple callables, you can also enqueue Task instances with Amp\Parallel\Worker\enqueue().

Documentation

Documentation can be found on amphp.org/parallel as well as in the ./docs directory.

Versioning

amphp/parallel follows the semver semantic versioning specification like all other amphp packages.

Security

If you discover any security related issues, please email me@kelunik.com instead of using the issue tracker.

License

The MIT License (MIT). Please see LICENSE for more information.

Development and Contributing

Want to hack on the source? A Vagrant box is provided with the repository to give a common development environment for running concurrent threads and processes, and comes with a bunch of handy tools and scripts for testing and experimentation.

Starting up and logging into the virtual machine is as simple as

vagrant up && vagrant ssh

Once inside the VM, you can install PHP extensions with Pickle, switch versions with newphp VERSION, and test for memory leaks with Valgrind.