PHP code example of sinacms / multiprocess

1. Go to this page and download the library: Download sinacms/multiprocess library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sinacms / multiprocess example snippets




use Mutilprocessing\Async;

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



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']); 



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));
});


// please pass $argv[1] to get args


use Mutilprocessing\Async;

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



use Mutilprocessing\Async;

Async::discard();

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"
  }
}