class Threading

Methods

call_func_multithreaded(callable $function, array $thread_params, int $max_threads = 20, bool|callable $log_callback = false)

Calls a Function with a number of number of different parameters via multi-threading.

int
call_user_func_array_in_new_process(callable $function, mixed $params, mixed $log_callback = false, string $thread_caption = false)

Starts a function in a new process. Returns the process id of the newly spawned process.. The called function should be self sustained, i.e. you cannot access any return params

string
getProcessCaption()

No description

bool
is_child_process()

Is the current process a child process?

bool
is_child_stopped(int $pid, $exit_status, int $wait_timeout = 0)

Check Status of a child process

sendSignalToRunningChildren(int $signal = SIGTERM)

Stops all running child processes

waitForRunningChildren()

Wait's until all child processes have been finished

Details

at line 41
call_func_multithreaded(callable $function, array $thread_params, int $max_threads = 20, bool|callable $log_callback = false)

Calls a Function with a number of number of different parameters via multi-threading.

A new process is spawned for each item in the $thread_params array, calling the $function and passing the item as the functions parameter. Once $max_threads threads have been spawned, the parent thread waits for child processes to finish before spawning new ones.

Parameters

callable $function

The callable function to call in each thread.

array $thread_params

An array of parameter arrays. A new thread is spawned for each item in this array.

int $max_threads

The maximum number of threads that are spawned simultaneously.

bool|callable $log_callback

A callable function that receives log messages

at line 96
int call_user_func_array_in_new_process(callable $function, mixed $params, mixed $log_callback = false, string $thread_caption = false)

Starts a function in a new process. Returns the process id of the newly spawned process.. The called function should be self sustained, i.e. you cannot access any return params

Parameters

callable $function

The function to call.

mixed $params

The parameters to pass to the function.

mixed $log_callback

A callable function that receives log messages.

string $thread_caption

Optional caption for thread. If false is provided the called function name will be used

Return Value

int

PID of process or false for unthreaded call

at line 232
string getProcessCaption()

No description

Return Value

string

Returns a verbose label for the current process / thread

at line 225
bool is_child_process()

Is the current process a child process?

Return Value

bool

True if this process has been spawned

at line 168
bool is_child_stopped(int $pid, $exit_status, int $wait_timeout = 0)

Check Status of a child process

Parameters

int $pid

Process ID

$exit_status

'RUNNING','EXIT','ABORTED' or 'UNKNOWN'

int $wait_timeout

How many seconds until we declare the thread hanging

Return Value

bool

at line 197
sendSignalToRunningChildren(int $signal = SIGTERM)

Stops all running child processes

Parameters

int $signal

POSIX SIGNAL

at line 207
waitForRunningChildren()

Wait's until all child processes have been finished