2017 © Pedro Peláez
 

library multiprocess

a tool for PHP multi process asynchronous tasks manage

image

sinacms/multiprocess

a tool for PHP multi process asynchronous tasks manage

  • Friday, July 6, 2018
  • by sunsky
  • Repository
  • 1 Watchers
  • 10 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 25 % Grown

The README.md

PHP Mutilprocess

This is high performance PHP Mutilprocessing Task Manager written in PHP, compatible with PHP-FPM and CLI.
这是一个用PHP编写的高性能PHP多进程异步任务管理器,与PHP FPM和CLI兼容。

Contents

Feature

  • By using this tool, PHP scripts can be invoked asynchronously based on multi processes, and finally wait for each process to return results, saving lots of time., (*1)

  • graceful and efficient, (*2)

  • can get callable function return value, (*3)

  • You can specify the PHP path for asynchronous execution scripts by specifying the phpBin parameter., (*4)

  • Exception Handling, (*5)

Installation

You can use composer to install this library from the command line., (*6)

composer require sinacms/multiprocess

Usage

distribute tasks and async execute

<?php

use Mutilprocessing\Async;

Async::create()->start('task.php', ['runTest'.$i]);

distribute tasks by a simple function and async execute

!!! WARN:please don't insert a '&&&' string in echo and return for some reason it will break down the program run, (*7)

<?php

use Mutilprocessing\Async;

Async::create()->startFunc(function($param1, $param2) {
    echo $param1.$param2.PHP_EOL;
}, ['param1' => 'hello', 'param2' => ' world']);

$func = function ($param1, $param2) {
    echo "this is an another func";
};

Async::create()->startFunc($func, ['param1' => 'hello', 'param2' => ' PHP']); 

sync wait for all process end

<?php

use Mutilprocessing\Async;
$outData = [];
Async::wait(function($code, $out, $err) use(&$outData) {
//    var_dump($code, $out, $err);
//  you can handle code runtime exception like this
     if (strlen($err) != 0) {
        //  do sth.
     }
     // and you can get return value like this
     // more function detail see examples :)
     array_push($outData, \Mutilprocessing\Async::getReturn($out));
});

outData structure:, (*8)

echos represent echos in execute, (*9)

returns represent return in execute, (*10)

array(4) {
  [0] =>
  array(2) {
    'echos' =>
    string(5) "hello"
    'returns' =>
    string(0) ""
  }
  [1] =>
  array(2) {
    'echos' =>
    string(6) "KZ RNG"
    'returns' =>
    string(10) "return 777"
  }
  [2] =>
  array(2) {
    'echos' =>
    string(17) "EDG AFSreturn 888"
    'returns' =>
    string(0) ""
  }
  [3] =>
  array(2) {
    'echos' =>
    string(6) "SKT RW"
    'returns' =>
    string(10) "return 666"
  }
}

getArgs passed from Async::start

// please pass $argv[1] to get args
<?php

use Mutilprocessing\Async;

Async::getArgs($argv[1], 'key');

clean all task

<?php

use Mutilprocessing\Async;

Async::discard();

Documentation

  • ### Async
    • ### option shorthand
  • public static function create()
  • public static function start($scriptname, $args, $phpBin="", $envs = [])
  • public function startFunc(callable $function, $args = [], $phpBin="")
  • public static function discard()
  • public static function wait(callable $logHandler = null)
  • public static function getArgs($argv = null)
  • public static function getReturn($out)
  • ### FunctionParser
    • ### option shorthand
  • public static function genTmp(callable $function)

Todo

  • regCallback for each execution (on process)
  • add multi execution unit and start once

The Versions

06/07 2018

dev-master

9999999-dev

a tool for PHP multi process asynchronous tasks manage

  Sources   Download

Apache-2.0

The Development Requires

by george wu
by Qingzhe Guo

php asynchronous async multi process

06/07 2018

1.1.0

1.1.0.0

a tool for PHP multi process asynchronous tasks manage

  Sources   Download

Apache-2.0

The Development Requires

by george wu
by Qingzhe Guo

php asynchronous async multi process

27/05 2018

1.0.1

1.0.1.0

a tool for PHP multi process asynchronous tasks manage

  Sources   Download

Apache-2.0

The Development Requires

by george wu
by Qingzhe Guo

php asynchronous async multi process

23/05 2018

1.0.0

1.0.0.0

a tool for PHP multi process asynchronous tasks manage

  Sources   Download

Apache-2.0

The Development Requires

by george wu

php asynchronous async multi process