php8.5
Home/ Manual/ reference / pthreads/ The Worker class

The Worker class

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

Intro

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

class Worker { }

Worker

In this section

Source: reference/pthreads/worker.xml · from the official PHP manual (php/doc-en)