hasantayyar/forker

将任务分割成多个分叉进程。

dev-master 2014-09-02 13:03 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:51:20 UTC


README

Build Status

Forker提供了一个简单的PHP分叉接口。

##本分叉有何不同 所有内容相同,但这个分叉是针对composer打包的。

安装

composer require hasantayyar/forker:dev-master

入门指南

<?php
use Hasantayyar\Forker\Forker;
$servers = array('machine1.example.com', 'machine2.example.com');

/**
 * Run a shell command on an array of servers using SSH,
 * returning the output and exit code.
 */
function runCmd($command, $servers) {
    return Forker::map($servers,
    function($index, $server) use ($command) {
        $sshCommand = "ssh $server -c '$command' 2>&1";
        exec($sshCommand, $exitCode, $output);
        return array(
            'output' => implode("\n", $output),
            'exitCode' => $exitCode
        );
    });
}

$results = runCmd("hostname", $servers);
print_r($results);

Circle CI