# The Worker class

(PECL pthreads >= 2.0.0)

## Einführung

Worker Threads have a persistent context, as such should be used over Threads in most cases.

When a Worker is started, the run method will be executed, but the Thread will not leave until one of the following conditions are met:

- the Worker goes out of scope (no more references remain)
- the programmer calls shutdown
- the script dies

This means the programmer can reuse the context throughout execution; placing objects on the stack of the Worker will cause the Worker to execute the stacked objects run method.

## Klassenbeschreibung

class Worker extends Thread implements Traversable, Countable, ArrayAccess {
/* Methoden */
public function collect(Callable `$collector` = ?): int
public function getStacked(): int
public function isShutdown(): bool
public function shutdown(): bool
public function stack(Threaded `&$work`): int
public function unstack(): int
/* Geerbte Methoden */
public function Thread::getCreatorId(): int
public static function Thread::getCurrentThread(): Thread
public static function Thread::getCurrentThreadId(): int
public function Thread::getThreadId(): int
public function Thread::isJoined(): bool
public function Thread::isStarted(): bool
public function Thread::join(): bool
public function Thread::start(int `$options` = ?): bool
}

## Inhaltsverzeichnis

- Worker::collect — Collect references to completed tasks
- Worker::getStacked — Gets the remaining stack size
- Worker::isShutdown — State Detection
- Worker::shutdown — Shutdown the worker
- Worker::stack — Stacking work
- Worker::unstack — Unstacking work

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open