(PECL pht >= 0.0.1)
pht\Thread::addFunctionTask — Function threading
Adds a new function task to a pht\Threads internal task queue.
func
The function to be threaded. If it is bound to an instance, then
$this
will become null
.
funcArgs
An optional list of arguments for the function. These arguments will be serialised (since they are being passed to another thread).
No return value.
Beispiel #1 Adding a new function task to a thread
<?php
use pht\Thread;
class Test
{
public static function run(){var_dump(5);}
public static function run2(){var_dump(6);}
}
function aFunc(){var_dump(3);}
$thread = new Thread();
$thread->addFunctionTask(static function($one) {var_dump($one);}, 1);
$thread->addFunctionTask(function() {var_dump(2);});
$thread->addFunctionTask('aFunc');
$thread->addFunctionTask('array_map', function ($n) {var_dump($n);}, [4]);
$thread->addFunctionTask(['Test', 'run']);
$thread->addFunctionTask([new Test, 'run2']);
$thread->start();
$thread->join();
Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
int(1) int(2) int(3) int(4) int(5) int(6)