• PHP Video Tutorials

PHP - Worker Functions



Worker class

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

Whenever a Worker class started, the run method can be executed. But the Thread class can't leave until one of the following conditions met −

  • Worker goes out of scope (no more references remain)
  • Programmer calls shutdown
  • Script dies

It means that a programmer can reuse the context throughout execution. Placing objects on the stack of Worker can cause the Worker to execute the stacked objects run method.

Class synopsis

Worker extends Thread implements Traversable , Countable , ArrayAccess {
   /* Methods */
   public int collect ([ Callable $collector ] )
   public int getStacked ( void )
   public bool isShutdown ( void )
   public boolean isWorking ( void )
   public bool shutdown ( void )
   public int stack ( Threaded &$work )
   public int unstack ( void )
   
   /* Inherited methods */
   public void Thread::detach ( void )
   public integer Thread::getCreatorId ( void )
   public static Thread Thread::getCurrentThread ( void )
   public static integer Thread::getCurrentThreadId ( void )
   public integer Thread::getThreadId ( void )
   public static mixed Thread::globally ( void )
   public boolean Thread::isJoined ( void )
   public boolean Thread::isStarted ( void )
   public boolean Thread::join ( void )
   public void Thread::kill ( void )
   public boolean Thread::start ([ integer $options ] )
}
Sr.No Function & Description
1

Worker::collect()

Function can collect references to completed tasks.

2

Worker::getStacked()

Function can get the remaining stack size.

3

Worker::isShutdown()

Function can tell if a referenced Worker has been shutdown.

4

Worker::isWorking()

Function can can tell if Worker is executing Stackables.

5

Worker::shutdown()

Function can shutdown the Worker after executing all Stackables previously stacked.

6

Worker::stack()

Function can return new length of a stack.

php_function_reference.htm
Advertisements