pthreads
PHP Manual

The Worker class

(PECL pthreads >= 2.0.0)

Introduction

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.

Class synopsis

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

Table of Contents


pthreads
PHP Manual