Download the PHP package mehr-als-nix/parallel without Composer

On this page you can find all versions of the php package mehr-als-nix/parallel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package parallel

Parallel

This is a library for introducing Parallelization into your project. See the example.php file for an example how to use this library.

Theory of Operation

This library will enable the developer to execute a given amount of tasks (workers) in parallel. This is achieved by adding workers onto a manager, optionally defining how many processes to run simultaneously and then execute the manager.

Under Linux this library will try to detect the number of processors and allow a maximum number of processes to run equal to the number of processors. If this cannot be determined or the user is running Windows then a default of 2 is used.

Requirements and graceful degradation

Parallelization has several requirements. But to allow distribution, without adding several requirements to your application, will this library execute the given tasks in serie if the requirements are not met. And throw a E_USER_NOTICE php error that explains to the user that dependencies are missing.

The requirements for this library are:

Workers

Workers are basically wrappers around callback functions or methods. As such you can use anything in your existing project and parallelize it.

Do note that each parallel process is a duplicate of the original. This means that, for example, if you pass an object (or other reference) and change that, that the changes that you have made do not carry over to the caller.

The return value of the given callback is stored as result on the worker and can be read using the getResult() method.

Any exception that is thrown will result in an error, where the getReturnCode() method will return the exception code (be warned: this may be 0!) and the getError() method will return the exception message.

Errors and exceptions

if a task throws an exception it is caught and registered as an error. The exception's code is used as error number, where the message is used as error message.

By using this, instead of dying, you can continue execution of the other parallel processes and handle errors yourself after all processes have been executed.

Examples

Fluent interface

use MehrAlsNix\Parallel\Manager;
use MehrAlsNix\Parallel\Worker;

$mgr = new Manager();
$mgr
  ->addWorker(new Worker(function() { sleep(1); return 'a'; }))
  ->addWorker(new Worker(function() { sleep(1); return 'b'; }))
  ->addWorker(new Worker(function() { sleep(1); return 'c'; }))
  ->addWorker(new Worker(function() { sleep(1); return 'd'; }))
  ->addWorker(new Worker(function() { sleep(1); return 'e'; }))
  ->execute();

/** @var Worker $worker */
foreach ($mgr as $worker) {
    var_dump($worker->getResult());
}

Array interface

use MehrAlsNix\Parallel\Manager;
use MehrAlsNix\Parallel\Worker;

$mgr = new Manager();
$mgr[] = new Worker(function() { sleep(1); return 'f'; });
$mgr[] = new Worker(function() { sleep(1); return 'g'; });
$mgr[] = new Worker(function() { sleep(1); return 'h'; });
$mgr[] = new Worker(function() { sleep(1); return 'i'; });
$mgr[] = new Worker(function() { sleep(1); return 'j'; });
$mgr->execute();

/** @var Worker $worker */
foreach ($mgr as $worker) {
    var_dump($worker->getResult());
}

TODO


All versions of parallel with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mehr-als-nix/parallel contains the following files

Loading the files please wait ...