承接 geopal-solutions/gnu-parallel-wrapper 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

geopal-solutions/gnu-parallel-wrapper

Composer 安装命令:

composer require geopal-solutions/gnu-parallel-wrapper

包简介

A wrapper library for the GNU Parallel binary

README 文档

README

Simple PHP wrapper class for the GNU Parallel tool. Allows for running single threaded tasks in parallel on one or multiple machines, from within PHP.

This package requires GNU Parallel to be installed beforehand!

In case you do not have Parallel on the machine you are running your PHP script on, an InvalidBinaryException will be thrown. (See examples.)

Example 1

/**
 *
 * Running commands on the local host
 *
 */

use Parallel\Exceptions\InvalidBinaryException;
use Parallel\Wrapper;

// You can initialize the Wrapper with or without parameters
$parallel = new Wrapper();

try {
    // Set path to binary
    $parallel->initBinary('/path/to/parallel/binary');

    // Add the commands you want to run in parallel
    $parallel->addCommand('/path/to/command/one.sh');
    $parallel->addCommand('/path/to/command/two.sh');
    $parallel->addCommand('/path/to/command/three.sh');

    /**
     * Setting the parallelism to 0 or "auto" will
     * result in a parallelism setting equal to the
     * number of commands you whish to run
     *
     * Use the maxParallelism setting to set a cap
     */
    $parallel->setParallelism('auto');
    $parallel->setMaxParallelism(10);

    // Run the commands and catch the output from the console
    $output = $parallel->run();
} catch (InvalidBinaryException $exception) {
    // The binary file does not exist, or is not executable
}

Example 2

/**
 *
 * Running commands on multiple hosts
 *
 */

use Parallel\Exceptions\InvalidBinaryException;
use Parallel\Wrapper;

$commands = array(
    '/path/to/command/one.sh',
    '/path/to/command/two.sh',
    '/path/to/command/three.sh'
);

$maxParallelism = 10;

// You can initialize the Wrapper with or without parameters
$parallel = new Wrapper('/path/to/parallel/binary', $commands, $maxParallelism);

try {
    /**
     * You can still set the parallelism manually, or leave it
     * to the wrapper to calculate it
     */
    $parallel->setParallelism(8);

    $parallel->addServer('foo@example1.com');
    $parallel->addServer('bar@example2.com');
    $parallel->addServer('baz@example3.com');

    /**
     * By default, the local host is also included
     * in the list of servers used for execution.
     * 
     * You can exclude it from the list by setting
     * the remoteOnly flag to true 
     */
    $parallel->useRemoteOnly(true);

    // Run the commands and catch the output from the console
    $output = $parallel->run();
} catch (InvalidBinaryException $exception) {
    // The binary file does not exist, or is not executable
}

统计信息

  • 总下载量: 2.98k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-01-31