Worker
class Worker extends Thread implements Traversable, Countable, ArrayAccess (View source)
(PECL pthreads >= 2.0.0)
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
Properties
protected Worker | $worker | Worker object in which this Threaded is being executed |
from Threaded |
Methods
(PECL pthreads >= 3.0.0)
Increments the internal number of references to a Threaded object
(PECL pthreads >= 2.0.0)
Fetches a chunk of the objects property table of the given size,
optionally preserving keys
(PECL pthreads >= 3.0.0)
Decrements the internal number of references to a Threaded object
(PECL pthreads >= 2.0.8)
Makes thread safe standard class at runtime
(PECL pthreads >= 3.0.0)
Retrieves the internal number of references to a Threaded object
(PECL pthreads >= 2.0.0)
Tell if the referenced object was terminated during execution; suffered
fatal errors, or threw uncaught exceptions
(PECL pthreads >= 2.0.0)
Merges data into the current object
(PECL pthreads >= 3.0.0)
Send notification to the referenced object. This unblocks at least one
of the blocked threads (as opposed to unblocking all of them, as seen with
Threaded::notify()).
(PECL pthreads >= 2.0.0)
The programmer should always implement the run method for objects
that are intended for execution.
(PECL pthreads >= 2.0.0)
Executes the block while retaining the referenced objects
synchronization lock for the calling context
(PECL pthreads >= 2.0.0)
Will cause the calling context to wait for notification from the
referenced object
(PECL pthreads >= 2.0.0)
Will return the identity of the Thread that created the referenced Thread
(PECL pthreads >= 2.0.0)
Return a reference to the currently executing Thread
(PECL pthreads >= 2.0.0)
Will return the identity of the currently executing Thread
(PECL pthreads >= 2.0.0)
Will return the identity of the referenced Thread
(PECL pthreads >= 2.0.0)
Causes the calling context to wait for the referenced Thread to finish executing
(PECL pthreads >= 2.0.0)
Will start a new Thread to execute the implemented run method
(PECL pthreads >= 3.0.0)
Allows the worker to collect references determined to be garbage by the
optionally given collector
(PECL pthreads >= 2.0.0)
Returns the number of tasks left on the stack
(PECL pthreads >= 2.0.0)
Whether the worker has been shutdown or not
(PECL pthreads >= 2.0.0)
Shuts down the Worker after executing all of the stacked tasks
Details
void
addRef()
(PECL pthreads >= 3.0.0)
Increments the internal number of references to a Threaded object
array
chunk(int $size, bool $preserve = false)
(PECL pthreads >= 2.0.0)
Fetches a chunk of the objects property table of the given size,
optionally preserving keys
int
count()
(PECL pthreads >= 2.0.0)
Returns the number of properties for this object
void
delRef()
(PECL pthreads >= 3.0.0)
Decrements the internal number of references to a Threaded object
static bool
extend(string $class)
(PECL pthreads >= 2.0.8)
Makes thread safe standard class at runtime
int
getRefCount()
(PECL pthreads >= 3.0.0)
Retrieves the internal number of references to a Threaded object
bool
isRunning()
(PECL pthreads >= 2.0.0)
Tell if the referenced object is executing
bool
isGarbage()
(PECL pthreads >= 3.1.0)
bool
isTerminated()
(PECL pthreads >= 2.0.0)
Tell if the referenced object was terminated during execution; suffered
fatal errors, or threw uncaught exceptions
bool
merge($from, $overwrite = true)
(PECL pthreads >= 2.0.0)
Merges data into the current object
bool
notify()
(PECL pthreads >= 2.0.0)
Send notification to the referenced object
bool
notifyOne()
(PECL pthreads >= 3.0.0)
Send notification to the referenced object. This unblocks at least one
of the blocked threads (as opposed to unblocking all of them, as seen with
Threaded::notify()).
mixed
pop()
(PECL pthreads >= 2.0.0)
Pops an item from the objects property table
void
run()
(PECL pthreads >= 2.0.0)
The programmer should always implement the run method for objects
that are intended for execution.
mixed
shift()
(PECL pthreads >= 2.0.0)
Shifts an item from the objects property table
mixed
synchronized(Closure $block, mixed ...$_)
(PECL pthreads >= 2.0.0)
Executes the block while retaining the referenced objects
synchronization lock for the calling context
bool
wait(int $timeout = 0)
(PECL pthreads >= 2.0.0)
Will cause the calling context to wait for notification from the
referenced object
bool
offsetExists(TKey $offset)
No description
mixed
offsetGet(TKey $offset)
No description
void
offsetSet(TKey $offset, TValue $value)
No description
void
offsetUnset(TKey $offset)
No description
int
getCreatorId()
(PECL pthreads >= 2.0.0)
Will return the identity of the Thread that created the referenced Thread
static Thread
getCurrentThread()
(PECL pthreads >= 2.0.0)
Return a reference to the currently executing Thread
static int
getCurrentThreadId()
(PECL pthreads >= 2.0.0)
Will return the identity of the currently executing Thread
int
getThreadId()
(PECL pthreads >= 2.0.0)
Will return the identity of the referenced Thread
bool
isJoined()
(PECL pthreads >= 2.0.0)
Tell if the referenced Thread has been joined
bool
isStarted()
(PECL pthreads >= 2.0.0)
Tell if the referenced Thread was started
bool
join()
(PECL pthreads >= 2.0.0)
Causes the calling context to wait for the referenced Thread to finish executing
bool
start(int $options = PTHREADS_INHERIT_ALL)
(PECL pthreads >= 2.0.0)
Will start a new Thread to execute the implemented run method
int
collect(callable|null $collector = null)
(PECL pthreads >= 3.0.0)
Allows the worker to collect references determined to be garbage by the
optionally given collector
int
getStacked()
(PECL pthreads >= 2.0.0)
Returns the number of tasks left on the stack
bool
isShutdown()
(PECL pthreads >= 2.0.0)
Whether the worker has been shutdown or not
bool
shutdown()
(PECL pthreads >= 2.0.0)
Shuts down the Worker after executing all of the stacked tasks
int
stack(Threaded $work)
(PECL pthreads >= 2.0.0)
Appends the new work to the stack of the referenced worker
Threaded|null
unstack()
(PECL pthreads >= 2.0.0)
Removes the first task (the oldest one) in the stack