OpenSwoole Multiprocessing

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Taking advantage of multicore, you have to use multiple processes in you server or application. You can build multiple processes application easily with the features provided by OpenSwoole.

Create and manage multiple processes

Multiple processes can run simultaneously (without context-switching) in multi-core processors. You can create multiple Linux processes in several ways:

  1. Define and manage multiple Worker processes in Server.
  2. Define and manage multiple Task Worker processes in Server.
  3. Create and manage one process with OpenSwoole Process.
  4. Create and manage multiple identical processes with OpenSwoole Process Pool.
  5. Create and manage multiple processes with OpenSwoole Process Manager.
  6. You can use fork or pcntl_fork.

Share data across multiple processes

  1. Use multiple process safe counter defined with OpenSwoole Atomic.
  2. Use OpenSwoole Table as in memory KV storage.

Interprocess synchronization

  1. Use OpenSwoole Atomic wait and wakeup for synchronization.
  2. Use OpenSwoole Lock for process synchronization.

Notice: process level synchronization should not be used within coroutine context

Last updated on September 1, 2022