GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Downloads
  • Documentation
  • Get Involved
  • Help
  • Getting Started
  • Introduction
  • A simple tutorial
  • Language Reference
  • Basic syntax
  • Types
  • Variables
  • Constants
  • Expressions
  • Operators

This view

  • Original page
  • New address

GeezerVison is showing www.php.net — PHP: parallel - Manual

PHP 8.6.0 RC5 available for testing
    Installation »
    « system
    • Preface
    • Function Reference
    • Process Control Extensions

    parallel

    Introduction

    parallel is a parallel concurrency extension for PHP ≥ 7.2.0. As of parallel 1.2.0, PHP ≥ 8.0.0 is required.

    A brief description of the concepts core to parallel follows, more detailed information may be found within this section of the manual.

    Runtime

    A parallel\Runtime represents a PHP interpreter thread. A parallel\Runtime is configured with an optional bootstrap file passed to parallel\Runtime::__construct(), this is typically an autoloader, or some other preloading routine: The bootstrap file will be included before any task is executed.

    After construction the parallel\Runtime remains available until it is closed, killed, or destroyed by the normal scoping rules of PHP objects. parallel\Runtime::run() allows the programmer to schedule tasks for execution in parallel. A parallel\Runtime has a FIFO schedule, tasks will be executed in the order that they are scheduled.

    Functional API

    parallel implements a functional, higher level API on top of parallel\Runtime that provides a single function entry point to executing parallel code with automatic scheduling: parallel\run().

    Task

    A task is simply a Closure intended for parallel execution. The Closure may contain almost any instruction, including nested closures. However, there are some instructions that are prohibited in tasks:

    • yield

    • use by-reference

    • declare class

    • declare named function

    Note:

    Nested closures may yield or use by-reference, but must not contain class or named function declarations.

    Note:

    No instructions are prohibited in the files which the task may include.

    Future

    The parallel\Future is used to access the return value from the task, and exposes an API for cancellation of the task.

    Channel

    A task may be scheduled with arguments, use lexical scope variables (by-value), and return a value (via a parallel\Future), but these only allow uni-directional communication: They allow the programmer to send data into and retrieve data from a task, but do not allow bi-directional communication between tasks. The parallel\Channel API allows bi-directional communication between tasks, a parallel\Channel is a socket-like link between tasks that the programmer can use to send and receive data.

    Events

    The parallel\Events API implements a native feel (Traversable) event loop, and parallel\Events::poll() method. It allows the programmer to work with sets of channels and or futures. The programmer simply adds channels and futures to the event loop, optionally setting the input for writes with parallel\Events::setInput(), and enters into a foreach: parallel will read from and write to objects as they become available yielding parallel\Events\Event objects describing the operations that have occurred.

    See Also

    • Philosophy
    • Installation
    • Philosophy
    • Functional API
      • parallel\bootstrap — Bootstrapping
      • parallel\run — Execution
    • parallel\Runtime — The parallel\Runtime class
      • parallel\Runtime::__construct — Runtime Construction
      • parallel\Runtime::run — Execution
      • parallel\Runtime::close — Runtime Graceful Join
      • parallel\Runtime::kill — Runtime Join
    • parallel\Future — The parallel\Future class
      • parallel\Future::cancel — Cancellation
      • parallel\Future::cancelled — State Detection
      • parallel\Future::done — State Detection
      • parallel\Future::value — Resolution
    • parallel\Channel — The parallel\Channel class
      • parallel\Channel::__construct — Channel Construction
      • parallel\Channel::make — Access
      • parallel\Channel::open — Access
      • parallel\Channel::recv — Sharing
      • parallel\Channel::send — Sharing
      • parallel\Channel::close — Closing
    • parallel\Events — The parallel\Events class
      • parallel\Events::setBlocking — Behaviour
      • parallel\Events::setTimeout — Behaviour
      • parallel\Events::setInput — Input
      • parallel\Events::addChannel — Targets
      • parallel\Events::addFuture — Targets
      • parallel\Events::remove — Targets
      • parallel\Events::poll — Polling
    • parallel\Events\Input — The parallel\Events\Input class
      • parallel\Events\Input::add — Inputs
      • parallel\Events\Input::clear — Inputs
      • parallel\Events\Input::remove — Inputs
    • parallel\Events\Event — The parallel\Events\Event class
    • parallel\Events\Event\Type — The parallel\Events\Event\Type class
    • parallel\Sync — The parallel\Sync class
      • parallel\Sync::__construct — Construction
      • parallel\Sync::get — Access
      • parallel\Sync::set — Access
      • parallel\Sync::wait — Synchronization
      • parallel\Sync::notify — Synchronization
      • parallel\Sync::__invoke — Synchronization

    Found A Problem?

    Learn How To Improve This Page • Submit a Pull Request • Report a Bug
    +add a note

    User Contributed Notes

    There are no user contributed notes for this page.
    • Process Control Extensions
      • Eio
      • Ev
      • Expect
      • PCNTL
      • POSIX
      • Program execution
      • parallel
      • pthreads
      • Semaphore
      • Shared Memory
      • Sync
    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.