pht\Thread::addFunctionTask

(PECL pht >= 0.0.1)

pht\Thread::addFunctionTaskFunction threading

Description

public pht\Thread::addFunctionTask ( callable $func [, mixed $...funcArgs ] ) : void

Adds a new function task to a pht\Threads internal task queue.

Parameters

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).

Return Values

No return value.

Examples

Example #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();

The above example will output:

int(1)
int(2)
int(3)
int(4)
int(5)
int(6)